CentOS 7.2配置Apache服务httpd(上)

2019-01-17 02:14:19刘景俊

十、配置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]例如,在目录[/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]中添加的用户回答

十二、基本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