Apache简介

Stella981
• 阅读 508
  • http://blog.csdn.net/wh211212/article/details/52982917

  • 一、Apache简介

  • Apache HTTP Server(简称Apache)是Apache软件基金会的一个开放源代码的网页服务器软件,可以在大多数电脑操作系统中运行,由于其跨平台和安全性(尽管不断有新的漏洞被发现,但由于其开放源代码的特点,漏洞总能被很快修补。因此总合来说,其安全性还是相当高的。)。被广泛使用,是最流行的Web服务器软件之一。它快速、可靠并且可通过简单的API扩充,将Perl/Python等解释器编译到服务器中。

  • 软件图标 
    Apache简介

  • 二、安装Apache httpd

  • 安装httpd以配置Web服务器, HTTP使用80 / TCP

  •   [1] 安装 httpd.
      [root@linuxprobe ~]# yum -y install httpd
      # 删除默认欢迎页面
      [root@linuxprobe ~]# rm -f /etc/httpd/conf.d/welcome.conf
      [2] 配置httpd,将服务器名称替换为您自己的环境
      [root@linuxprobe ~]# vi /etc/httpd/conf/httpd.conf
      # line 86: 改变管理员的邮箱地址
      ServerAdmin root@linuxprobe.org
      # line 95: 改变域名信息
      ServerName www.linuxprobe.org:80
      # line 151: none变成All
      AllowOverride All
      # line 164: 添加只能使用目录名称访问的文件名
      DirectoryIndex index.html index.cgi index.php
      # add follows to the end
      # server's response header(安全性)
      ServerTokens Prod
      # keepalive is ON
      KeepAlive On
      [root@linuxprobe ~]# systemctl start httpd
      [root@linuxprobe ~]# systemctl enable httpd
      [3] 如果Firewalld正在运行,请允许HTTP服务。,HTTP使用80 / TCP
      [root@linuxprobe ~]# firewall-cmd --add-service=http --permanent
      success
      [root@linuxprobe ~]# firewall-cmd --reload
      success
      [4] 创建一个HTML测试页,并使用Web浏览器从客户端PC访问它。如果显示以下页面,是正确的
      [root@linuxprobe ~]# vi /var/www/html/index.html
      <html>
      <body>
      <div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
      Welcome access LinuxProbe.org,This is Test Page!
      </div>
      </body>
      </html>
    
  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

  • 11

  • 12

  • 13

  • 14

  • 15

  • 16

  • 17

  • 18

  • 19

  • 20

  • 21

  • 22

  • 23

  • 24

  • 25

  • 26

  • 27

  • 28

  • 29

  • 30

  • 31

  • 32

  • 33

  • 34

  • 35

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

  • 11

  • 12

  • 13

  • 14

  • 15

  • 16

  • 17

  • 18

  • 19

  • 20

  • 21

  • 22

  • 23

  • 24

  • 25

  • 26

  • 27

  • 28

  • 29

  • 30

  • 31

  • 32

  • 33

  • 34

  • 35

  • Apache简介

  • 三、支持Perl

  • 启用CGI执行并使用Perl脚本

  •   [1] 安装Perl.
      [root@linuxprobe ~]# yum -y install perl perl-CGI
      [2] 默认情况下,在“/var/www/cgi-bin”目录下允许CGI。  
      可以使用Perl Scripts放在目录下。然而,它下面的所有文件都被处理为CGI。
      # 下面的设置是CGI的设置
      [root@linuxprobe ~]# grep -n "^ *ScriptAlias" /etc/httpd/conf/httpd.conf
      247: ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
      [3] 如果你想允许在其他目录中的CGI,配置如下。  
      例如,在“/var/www/html/cgi-enabled”中允许。
      [root@linuxprobe ~]# vi /etc/httpd/conf.d/cgi-enabled.conf
      # create new
      # processes .cgi and .pl as CGI scripts
      <Directory "/var/www/html/cgi-enabled">
          Options +ExecCGI
          AddHandler cgi-script .cgi .pl
      </Directory>
      [root@linuxprobe ~]# systemctl restart httpd
      [4] 如果SELinux被启用,并且允许CGI在不是像上面[3]的默认目录下,更改规则如下。
      [root@linuxprobe ~]# chcon -R -t httpd_sys_script_exec_t /var/linuxprobe/html/cgi-enabled
      [root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_script_exec_t /var/www/html/cgi-enabled
      [5] 创建一个CGI测试页面,并使用Web浏览器从客户端PC访问它。如果显示以下页面,说明配置正确。
      [root@linuxprobe ~]# vi /var/www/html/cgi-enabled/index.cgi
      #!/usr/bin/perl
      print "Content-type: text/html\n\n";
      print "<html>\n<body>\n";
      print "<div style=\"width: 100%; font-size: 40px; font-weight: bold; text-align: center;\">\n";
      print "CGI Test Page";
      print "\n</div>\n";
      print "</body>\n</html>\n";
      [root@linuxprobe ~]# chmod 705 /var/www/html/cgi-enabled/index.cgi 
    
  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

  • 11

  • 12

  • 13

  • 14

  • 15

  • 16

  • 17

  • 18

  • 19

  • 20

  • 21

  • 22

  • 23

  • 24

  • 25

  • 26

  • 27

  • 28

  • 29

  • 30

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

  • 11

  • 12

  • 13

  • 14

  • 15

  • 16

  • 17

  • 18

  • 19

  • 20

  • 21

  • 22

  • 23

  • 24

  • 25

  • 26

  • 27

  • 28

  • 29

  • 30

  • Apache简介

  • 四、支持PHP

  • 配置httpd以使用PHP脚本

  •   [1] 安装PHP.
      [root@linuxprobe ~]# yum -y install php php-mbstring php-pear
      [root@linuxprobe ~]# vi /etc/php.ini
      # line 878: 取消注释,设置时区
      date.timezone = "Asia/Shanghai"
      [root@linuxprobe ~]# systemctl restart httpd
        
      [2] 创建一个PHP测试页面,并使用Web浏览器从客户端PC访问它。如果显示以下页面,它是确定。
      [root@linuxprobe ~]# vi /var/www/html/index.php
      <html>
      <body>
      <div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
      <?php
         print Date("Y/m/d");
      ?>
      </div>
      </body>
      </html>
    
  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

  • 11

  • 12

  • 13

  • 14

  • 15

  • 16

  • 17

  • 18

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

  • 11

  • 12

  • 13

  • 14

  • 15

  • 16

  • 17

  • 18

  • Apache简介

  •   [3] 创建phpinfo测试页,确认是都开启php支持
      [root@linuxprobe ~]# echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php
    
  • 1

  • 2

  • 1

  • 2

  • Apache简介

  • 五、支持Ruby

  • 配置httpd以将Ruby脚本用作CGI

  •   [1] 安装Ruby.
      [root@linuxprobe ~]# yum -y install ruby
        
      [2] 默认情况下,在“/var/www/cgi-bin”目录下允许CGI。  
      可以使用Perl Scripts放在目录下。然而,它下面的所有文件都被处理为CGI。
      # 下面的设置是CGI的设置
      [root@linuxprobe ~]# grep -n "^ *ScriptAlias" /etc/httpd/conf/httpd.conf
      247: ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
      
      [3] 如果你想允许在其他目录中的CGI,配置如下。  
      例如,在“/var/www/html/cgi-enabled”中允许。
      [root@linuxprobe ~]# vi /etc/httpd/conf.d/cgi-enabled.conf
      # create new
      # processes .rb as CGI scripts
      <Directory "/var/www/html/cgi-enabled">
          Options +ExecCGI
          AddHandler cgi-script .rb
      </Directory>
      [root@linuxprobe ~]# systemctl restart httpd
      
      [4] 如果SELinux被启用,并且允许CGI在不是像上面[3]的默认目录下,更改规则如下。
      [root@linuxprobe ~]# chcon -R -t httpd_sys_script_exec_t /var/www/html/cgi-enabled
      
      [root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_script_exec_t /var/www/html/cgi-enabled
      
      [5]     Create a CGI test page and access to it from client PC with web browser. It's OK if following page is shown.
      [root@linuxprobe ~]# vi /var/www/html/cgi-enabled/index.rb
      
      #!/usr/bin/ruby
      print "Content-type: text/html\n\n"
      print "<html>\n<body>\n"
      print "<div style=\"width: 100%; font-size: 40px; font-weight: bold; text-align: center;\">\n"
      print "Ruby Script Test Page"
      print "\n</div>\n"
      print "</body>\n</html>\n" 
      [root@linuxprobe ~]# chmod 705 /var/www/html/cgi-enabled/index.rb 
    
  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

  • 11

  • 12

  • 13

  • 14

  • 15

  • 16

  • 17

  • 18

  • 19

  • 20

  • 21

  • 22

  • 23

  • 24

  • 25

  • 26

  • 27

  • 28

  • 29

  • 30

  • 31

  • 32

  • 33

  • 34

  • 35

  • 36

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

  • 11

  • 12

  • 13

  • 14

  • 15

  • 16

  • 17

  • 18

  • 19

  • 20

  • 21

  • 22

  • 23

  • 24

  • 25

  • 26

  • 27

  • 28

  • 29

  • 30

  • 31

  • 32

  • 33

  • 34

  • 35

  • 36

  • Apache简介

  • 六、支持Python

  • 启用CGI执行并使用Python脚本

  •   [1] 安装python.
      [root@linuxprobe ~]# yum -y install python
        
      [2] 默认情况下,在“/var/www/cgi-bin”目录下允许CGI。  
      可以使用Perl Scripts放在目录下。然而,它下面的所有文件都被处理为CGI。
      # 下面的设置是CGI的设置
      [root@linuxprobe ~]# grep -n "^ *ScriptAlias" /etc/httpd/conf/httpd.conf
      247: ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
      
      [3] 如果你想允许在其他目录中的CGI,配置如下。  
      例如,在“/var/www/html/cgi-enabled”中允许。
      [root@linuxprobe ~]# vi /etc/httpd/conf.d/cgi-enabled.conf
      # create new
      # processes .py as CGI scripts
      <Directory "/var/www/html/cgi-enabled">
          Options +ExecCGI
          AddHandler cgi-script .py
      </Directory>
      [root@linuxprobe ~]# systemctl restart httpd
      
      [4] 如果SELinux被启用,并且允许CGI在不是像上面[3]的默认目录下,更改规则如下。
      [root@linuxprobe ~]# chcon -R -t httpd_sys_script_exec_t /var/www/html/cgi-enabled
      [root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_script_exec_t /var/www/html/cgi-enabled
      
      [5]     Create a CGI test page and access to it from client PC with web browser. It's OK if following page is shown.
      [root@linuxprobe ~]# vi /var/www/html/cgi-enabled/index.py
      
      #!/usr/bin/env python
      
      print "Content-type: text/html\n\n"
      print "<html>\n<body>\n"
      print "<div style=\"width: 100%; font-size: 40px; font-weight: bold; text-align: center;\">\n"
      print "Python Script Test Page"
      print "\n</div>\n"
      print "</body>\n</html>\n" 
      
      [root@linuxprobe ~]# chmod 705 /var/www/html/cgi-enabled/index.py
    
  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

  • 11

  • 12

  • 13

  • 14

  • 15

  • 16

  • 17

  • 18

  • 19

  • 20

  • 21

  • 22

  • 23

  • 24

  • 25

  • 26

  • 27

  • 28

  • 29

  • 30

  • 31

  • 32

  • 33

  • 34

  • 35

  • 36

  • 37

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

  • 11

  • 12

  • 13

  • 14

  • 15

  • 16

  • 17

  • 18

  • 19

  • 20

  • 21

  • 22

  • 23

  • 24

  • 25

  • 26

  • 27

  • 28

  • 29

  • 30

  • 31

  • 32

  • 33

  • 34

  • 35

  • 36

  • 37

  • Apache简介

  • 7、支持Userdir

  • 启用userdir,用户可以使用此设置创建网站

  •   [1] 配置 httpd.
      [root@linuxprobe ~]# vi /etc/httpd/conf.d/userdir.conf
      # line 17: comment out
      #UserDir disabled
      # line 24: uncomment
      UserDir public_html
      # line 31 - 35
        
      <Directory "/home/*/public_html">
          AllowOverride All
      # change
      
          Options None
      # change
      
          Require method GET POST OPTIONS
      </Directory>
      [root@linuxprobe ~]# systemctl restart httpd
      
      [2] 创建一个测试页,使用普通用户通过客户端PC与Web浏览器和访问它,如果显示以下页面,就是正确的
      [cent@linuxprobe ~]$ mkdir public_html
      
      [cent@linuxprobe ~]$ chmod 711 /home/cent
      
      [cent@linuxprobe ~]$ chmod 755 /home/cent/public_html
      
      [cent@linuxprobe ~]$ vi ./public_html/index.html
      
      <html>
      <body>
      <div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
      UserDir Test Page
      </div>
      </body>
      </html>
    
  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

  • 11

  • 12

  • 13

  • 14

  • 15

  • 16

  • 17

  • 18

  • 19

  • 20

  • 21

  • 22

  • 23

  • 24

  • 25

  • 26

  • 27

  • 28

  • 29

  • 30

  • 31

  • 32

  • 33

  • 34

  • 35

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

  • 11

  • 12

  • 13

  • 14

  • 15

  • 16

  • 17

  • 18

  • 19

  • 20

  • 21

  • 22

  • 23

  • 24

  • 25

  • 26

  • 27

  • 28

  • 29

  • 30

  • 31

  • 32

  • 33

  • 34

  • 35

  • 浏览器访问:http://linuxprobe.org/~wang/,出现如下界面 

  • Apache简介

  • 8、设置虚拟主机

  • 配置虚拟主机以使用多个域名。 
    以下示例在域名为[linuxprobe.org],虚拟域名为[virtual.host(根目录[/home/wang/public_html]]的环境中设置。 
    必须为此示例设置Userdir的设置

  •   [1] 配置虚拟主机
      [root@linuxprobe ~]# vi /etc/httpd/conf.d/vhost.conf
      # for original domain
        
      <VirtualHost *:80>
         DocumentRoot /var/www/html
         ServerName www.linuxprobe.org
      </VirtualHost>
      # for virtual domain
      
      <VirtualHost *:80>
         DocumentRoot /home/cent/public_html
         ServerName www.virtual.host
         ServerAdmin webmaster@virtual.host
         ErrorLog logs/virtual.host-error_log
         CustomLog logs/virtual.host-access_log combined
      </VirtualHost>
      [root@linuxprobe ~]# systemctl restart httpd
      
      [2]创建测试页并使用Web浏览器从客户端计算机访问它。如果显示以下页面,则是正确的:
      [cent@linuxprobe ~]$ vi ~/public_html/virtual.php
      <html>
      <body>
      <div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
      Virtual Host Test Page
      </div>
      </body>
      </html>
      [3]如果访问测试时看不到相应页面,可通过下面命令进行测试:
      [root@linuxprobe ~]# yum -y install elinks^C
      [root@linuxprobe ~]# elinks http://www.virtual.host/virtual.php
    
  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

  • 11

  • 12

  • 13

  • 14

  • 15

  • 16

  • 17

  • 18

  • 19

  • 20

  • 21

  • 22

  • 23

  • 24

  • 25

  • 26

  • 27

  • 28

  • 29

  • 30

  • 31

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

  • 11

  • 12

  • 13

  • 14

  • 15

  • 16

  • 17

  • 18

  • 19

  • 20

  • 21

  • 22

  • 23

  • 24

  • 25

  • 26

  • 27

  • 28

  • 29

  • 30

  • 31

  • 9、创建SSL证书

  • 创建自己的SSL证书。但是,如果您使用您的服务器作为业务,最好购买和使用来自Verisigh的正式证书等。

  •   [root@linuxprobe ~]# cd /etc/pki/tls/cert
      cert.pem  certs/    
      [root@linuxprobe ~]# cd /etc/pki/tls/certs/
      [root@linuxprobe certs]# make server.key
      umask 77 ; \
      /usr/bin/openssl genrsa -aes128 2048 > server.key
      Generating RSA private key, 2048 bit long modulus
      ...............................................................+++
      ....................................................................................................+++
      e is 65537 (0x10001)
      Enter pass phrase:
      Verifying - Enter pass phrase:
      [root@linuxprobe certs]# openssl rsa -in server.key -out server.key
      Enter pass phrase for server.key:
      writing RSA key
      [root@linuxprobe certs]# make server.csr
      umask 77 ; \
      /usr/bin/openssl req -utf8 -new -key server.key -out server.csr
      You are about to be asked to enter information that will be incorporated
      into your certificate request.
      What you are about to enter is what is called a Distinguished Name or a DN.
      There are quite a few fields but you can leave some blank
      For some fields there will be a default value,
      If you enter '.', the field will be left blank.
      -----
      Country Name (2 letter code) [XX]:CN    #国家后缀
      State or Province Name (full name) []:Shanghai  #省
      Locality Name (eg, city) [Default City]:Shanghai  #市
      Organization Name (eg, company) [Default Company Ltd]:LinuxProbe  #公司
      Organizational Unit Name (eg, section) []:DevOps  #部门
      Common Name (eg, your name or your server's hostname) []:linuxprobe.org  #主机名
      Email Address []:root@linuxprobe.org  #邮箱
        
      Please enter the following 'extra' attributes
      to be sent with your certificate request
      A challenge password []:    #默认
      An optional company name []:    #默认
      #
      [root@linuxprobe certs]# openssl x509 -in server.csr -out server.crt -req -signkey server.key -days 3650
      Signature ok
      subject=/C=CN/ST=Shanghai/L=Shanghai/O=LinuxProbe/OU=DevOps/CN=linuxprobe.org/emailAddress=root@linuxprobe.org
      Getting Private key
      
    
  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

  • 11

  • 12

  • 13

  • 14

  • 15

  • 16

  • 17

  • 18

  • 19

  • 20

  • 21

  • 22

  • 23

  • 24

  • 25

  • 26

  • 27

  • 28

  • 29

  • 30

  • 31

  • 32

  • 33

  • 34

  • 35

  • 36

  • 37

  • 38

  • 39

  • 40

  • 41

  • 42

  • 43

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

  • 11

  • 12

  • 13

  • 14

  • 15

  • 16

  • 17

  • 18

  • 19

  • 20

  • 21

  • 22

  • 23

  • 24

  • 25

  • 26

  • 27

  • 28

  • 29

  • 30

  • 31

  • 32

  • 33

  • 34

  • 35

  • 36

  • 37

  • 38

  • 39

  • 40

  • 41

  • 42

  • 43

  • 10、配置SSL

  •   [1] 配置SSL.
      [root@linuxprobe ~]# yum -y install mod_ssl
      [root@linuxprobe ~]# vi /etc/httpd/conf.d/ssl.conf
      # line 59: 取消注释
      DocumentRoot "/var/www/html"
      # line 60: 取消注释,定义域名
      ServerName linuxprobe.org:443
      # line 75: 改变SSLProtocol
      SSLProtocol -All +TLSv1 +TLSv1.1 +TLSv1.2
        
      # line 100: 改成刚刚创建的server.crt
      SSLCertificateFile /etc/pki/tls/certs/server.crt
      # line 107: 改成刚刚创建的server.key
      SSLCertificateKeyFile /etc/pki/tls/certs/server.key
      [root@www ~]# systemctl restart httpd
      
      [2] 如果Firewalld正在运行,请允许HTTPS服务。 HTTPS使用443 / TCP
      [root@www ~]# firewall-cmd --add-service=https --permanent
      success
      [root@www ~]# firewall-cmd --reload
      success
      [3] 使用Web浏览器通过HTTPS从客户端计算机访问测试页。下面的示例是Fiorefix。显示以下屏幕,因为证书是自己创建的,但它没有ploblem,继续下一步。
    
  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

  • 11

  • 12

  • 13

  • 14

  • 15

  • 16

  • 17

  • 18

  • 19

  • 20

  • 21

  • 22

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

  • 11

  • 12

  • 13

  • 14

  • 15

  • 16

  • 17

  • 18

  • 19

  • 20

  • 21

  • 22

  • Apache简介

  • 11、启用基本身份验证

  • 启用基本身份验证以限制特定网页的访问

  •   [1]例如,在目录[/var/www/html/auth-basic]下设置基本身份验证设置。
       [root@linuxprobe ~]# vi /etc/httpd/conf.d/auth_basic.conf
      # 创建新配置文件
      <Directory /var/www/html/auth-basic>
          AuthType Basic
          AuthName "Basic Authentication"
          AuthUserFile /etc/httpd/conf/.htpasswd
          require valid-user
      </Directory>
      # 添加用户:使用“-c”创建新文件(仅为初始注册添加“-c”选项)
      [root@linuxprobe ~]# htpasswd -c /etc/httpd/conf/.htpasswd wang
        
      New password: # set password
      
      Re-type new password: # confirm
      
      Adding password for user wang
      [root@linuxprobe ~]# systemctl restart httpd
      [root@linuxprobe ~]# mkdir /var/www/html/auth-basic
      
      [root@linuxprobe ~]# vi /var/www/html/auth-basic/index.html
      # create a test page
      
      <html>
      <body>
      <div style="width: 100%; font-size: 40px; font-weight: bold; text-align: wanger;">
      Test Page for Basic Auth
      </div>
      </body>
      </html>
      
      [2] 使用Web浏览器从客户端计算机访问测试页。然后需要认证,如下所示作为设置,用在[1]中添加的用户回答
    
  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

  • 11

  • 12

  • 13

  • 14

  • 15

  • 16

  • 17

  • 18

  • 19

  • 20

  • 21

  • 22

  • 23

  • 24

  • 25

  • 26

  • 27

  • 28

  • 29

  • 30

  • 31

  • 32

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

  • 11

  • 12

  • 13

  • 14

  • 15

  • 16

  • 17

  • 18

  • 19

  • 20

  • 21

  • 22

  • 23

  • 24

  • 25

  • 26

  • 27

  • 28

  • 29

  • 30

  • 31

  • 32

  • Apache简介  

  • [3] 访问成功 

  • Apache简介

  • 12、基本Auth + PAM

  • 限制特定网页上的访问,并使用OS用户通过SSL连接进行身份验证

  •   [1] 创建证书,请参照上文所述。
      [2] 例如,在[/var/www/html/auth-pam]目录下设置Basic Auth。
      # install from EPEL
      [root@linuxprobe ~]# yum --enablerepo=epel -y install mod_authnz_external pwauth
      [root@linuxprobe ~]# vi /etc/httpd/conf.d/authnz_external.conf
      # add to the end
        
      <Directory /var/www/html/auth-pam>
          SSLRequireSSL
          AuthType Basic
          AuthName "PAM Authentication"
          AuthBasicProvider external
          AuthExternal pwauth
          require valid-user
      </Directory>
      
      [root@linuxprobe ~]# mkdir /var/www/html/auth-pam
      
      [root@linuxprobe ~]# vi /var/www/html/auth-pam/index.html
      # create a test page
      
      <html>
      <body>
      <div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
      Test Page for PAM Auth
      </div>
      </body>
      </html>
      
      [root@linuxprobe ~]# systemctl restart httpd
      [3]  在客户端上使用Web浏览器访问测试页面https://linuxprobe.org/auth-pam/,并与操作系统上的用户进行身份验证。
    
  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

  • 11

  • 12

  • 13

  • 14

  • 15

  • 16

  • 17

  • 18

  • 19

  • 20

  • 21

  • 22

  • 23

  • 24

  • 25

  • 26

  • 27

  • 28

  • 29

  • 30

  • 31

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

  • 11

  • 12

  • 13

  • 14

  • 15

  • 16

  • 17

  • 18

  • 19

  • 20

  • 21

  • 22

  • 23

  • 24

  • 25

  • 26

  • 27

  • 28

  • 29

  • 30

  • 31

  • Apache简介  

  • Apache简介

  • 13、使用WebDAV

  • 下面是使用SSL连接配置WebDAV设置的示例

  •   [1] 创建证书,请参照上文所述
      [2] 例如,创建一个目录[webdav],它使得可以仅通过SSL连接到WebDAV目录。
      [root@linuxprobe ~]# mkdir /home/webdav
      [root@linuxprobe ~]# chown apache. /home/webdav
      [root@linuxprobe ~]# chmod 770 /home/webdav
      [root@linuxprobe ~]# vi /etc/httpd/conf.d/webdav.conf
      # create new
      DavLockDB "/tmp/DavLock"
      Alias /webdav /home/webdav
      <Location /webdav>
          DAV On
          SSLRequireSSL
          Options None
          AuthType Basic
          AuthName WebDAV
          AuthUserFile /etc/httpd/conf/.htpasswd
          <RequireAny>
              Require method GET POST OPTIONS
              Require valid-user
          </RequireAny>
      </Location>
        
      #  添加用户:使用“-c”创建新文件(仅为初始注册添加“-c”选项)
      [root@linuxprobe ~]# htpasswd -c /etc/httpd/conf/.htpasswd wang
      New password:     # set password
      Re-type new password:
      Adding password for user wang
      # **注意:用户wang的htpasswd已经创建过,不需要重复创建**
      [root@linuxprobe ~]# systemctl restart httpd
      
      [3]  如果启用了SELinux,请更改以下规则。  
      [root@linuxprobe ~]# chcon -R -t httpd_sys_rw_content_t /home/webdav
      [root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_rw_content_t /home/webdav
      
      [4]  这是PC上的WebDAV客户端的设置(Windows 10)。
      下载“CarotDAV”,这是一个免费的WebDAV客户端,从以下网站⇒ http://www.rei.to/carotdav_en.html ,下载后,安装并启动CarotDAV,然后显示以下屏幕,单击“文件”按钮并选择“WebDAV”。 
    
  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

  • 11

  • 12

  • 13

  • 14

  • 15

  • 16

  • 17

  • 18

  • 19

  • 20

  • 21

  • 22

  • 23

  • 24

  • 25

  • 26

  • 27

  • 28

  • 29

  • 30

  • 31

  • 32

  • 33

  • 34

  • 35

  • 36

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

  • 11

  • 12

  • 13

  • 14

  • 15

  • 16

  • 17

  • 18

  • 19

  • 20

  • 21

  • 22

  • 23

  • 24

  • 25

  • 26

  • 27

  • 28

  • 29

  • 30

  • 31

  • 32

  • 33

  • 34

  • 35

  • 36

  • Apache简介

  •   [5]在“设置名称”字段中输入任何名称,并在“URI”字段中输入[服务器名称/ webdav目录],并输入用户名和密码
    
  • 1

  • 1

  • Apache简介

  •   [7]配置添加如下,点击它连接到服务器。 
    
  • 1

  • 1

  • Apache简介

  •   [8] waring显示如下,它的SSL证书没有安装在您的电脑上,它没有ploblem,点击“忽略”,然后去下一步。 
    
  • 1

  • 1

  • Apache简介

  •   [9] 到webdav目录下创建测试目录和文件
      [root@linuxprobe tmp]# cd /home/webdav/
      [root@linuxprobe webdav]# mkdir linuxprobe
      [root@linuxprobe webdav]# mkdir linuxcool
      [root@linuxprobe webdav]# touch vdevops.txt
      [root@linuxprobe webdav]# touch linuxcool.txt
    
点赞
收藏
评论区
推荐文章
blmius blmius
2年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
Jacquelyn38 Jacquelyn38
3年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
待兔 待兔
2星期前
手写Java HashMap源码
HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22
Wesley13 Wesley13
2年前
Java获得今日零时零分零秒的时间(Date型)
publicDatezeroTime()throwsParseException{    DatetimenewDate();    SimpleDateFormatsimpnewSimpleDateFormat("yyyyMMdd00:00:00");    SimpleDateFormatsimp2newS
Wesley13 Wesley13
2年前
mysql设置时区
mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0
Wesley13 Wesley13
2年前
00:Java简单了解
浅谈Java之概述Java是SUN(StanfordUniversityNetwork),斯坦福大学网络公司)1995年推出的一门高级编程语言。Java是一种面向Internet的编程语言。随着Java技术在web方面的不断成熟,已经成为Web应用程序的首选开发语言。Java是简单易学,完全面向对象,安全可靠,与平台无关的编程语言。
Stella981 Stella981
2年前
Django中Admin中的一些参数配置
设置在列表中显示的字段,id为django模型默认的主键list_display('id','name','sex','profession','email','qq','phone','status','create_time')设置在列表可编辑字段list_editable
Wesley13 Wesley13
2年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Python进阶者 Python进阶者
6个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这