Apache密码管理 和 SSL访问

使用url传递密码,访问网站
http://username:password@example.com/

yum install httpd-tools
/usr/bin/htpasswd

I put .htaccess in /var/www/html

AuthType Basic
AuthName “Restricted Access”
AuthUserFile /usr/local/apache/passwd/wwwpasswd
Require valid-user

mkdir -p /usr/local/apache/passwd
# Create as many usernames as you need.
htpasswd -c /usr/local/apache/passwd/wwwpasswd someusername
htpasswd -c /usr/local/apache/passwd/wwwpasswd someotherusername

Alternatively, the authentication can be added to the bottom of /etc/httpd/conf/httpd.conf as follows.

AuthType Basic
AuthName “Restricted Area”
AuthUserFile /usr/local/apache/passwd/wwwpasswd
Require valid-user

or
If browser http access is only required from certain IP addresses or ranges of addresses.
nano /etc/httpd/conf.d/whitelist.conf

Order Deny,Allow
Deny from all
#
Allow from x.x.x.x
Allow from x.x.x.x x.x.x.x x.x.x.x
Allow from somedomain.com
Allow from x.x
Allow from x.x.x.0/255.255.255.0
#
#See http://httpd.apache.org/docs/2.2/mod/mod_authz_host.html for more examples
#

设置SSL

yum install mod_ssl
mkdir /etc/httpd/ssl
creating the self-signed SSL certificate and the server key that protects it, and placing both of them into the new directory.
openssl req -x509 -nodes -days 730 -newkey rsa:2048 -keyout /etc/httpd/ssl/apache.key -out /etc/httpd/ssl/apache.crt
vi /etc/httpd/conf.d/ssl.conf

Find the following three lines, and make sure that they match the extensions below:

SSLEngine on
SSLCertificateFile /etc/httpd/ssl/apache.crt
SSLCertificateKeyFile /etc/httpd/ssl/apache.key

/etc/init.d/httpd restart

发表评论

电子邮件地址不会被公开。 必填项已用*标注