13、为第4题中的nginx服务的第二个虚拟机建立访问控制,要求:
1)为此虚拟主机提供基本认证功能,并为其提供两个虚拟用户webuser1和webuser2,密码均为RedHat,要求允许此两用户在提供密码的情况下访问此站点;
参考答案:
# /usr/local/apache/bin/htpasswd -cm /etc/nginx/.htpasswd webuser1
# /usr/local/apache/bin/htpasswd -m /etc/nginx/.htpasswd webuser2
# vi /usr/local/nginx/conf/nginx.conf
server {
listen 8080;
server_name www2.linuxidc.com;
root /www/html/www2/;
index index.html;
access_log /var/log/nginx/www2.access;
error_log /var/log/nginx/www2.err;
auth_basic "Hi Buddy.";
auth_basic_user_file "/etc/nginx/.htpasswd";
location / {
allow 172.16.0.0/16;
deny all;
}
}
至此,已完成全部题目。nginx的web1和web2的最终配置为
附件
server {
listen 8080;
server_name www1.linuxidc.com;
root /www/html/www1;
index index.php index.html;
access_log /var/log/nginx/www1.access main;
error_log /var/log/nginx/www1.err;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
}
server {
listen 8080;
server_name www2.linuxidc.com;
root /www/html/www2/;
index index.html;
access_log /var/log/nginx/www2.access;
error_log /var/log/nginx/www2.err;
auth_basic "Hi Buddy.";
auth_basic_user_file "/etc/nginx/.htpasswd";
location / {
allow 172.16.0.0/16;
deny all;
}
}
