ajax nginx 转发 sessionid_Web服务器06下Nginx配置虚拟主机及访问控制
Web服务器06下-Nginx配置虚拟主机及访问控制
一、Nginx配置虚拟主机
1、基于域名的虚拟主机
示例:
[root@nginx ~]# vim /usr/local/nginx/conf/nginx.conf
[root@nginx ~]# ulimit -n 65000
[root@nginx ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@nginx ~]# killall -1 nginx
[root@nginx ~]# mkdir -p /web/www.amber.com
[root@nginx ~]# mkdir -p /web/mail.amber.com
[root@nginx ~]# echo "
www.amber.com
" >/web/www.amber.com/index.html
[root@nginx ~]# echo "
mail.amber.com
" >/web/mail.amber.com/index.html
客户机测试:
2、基于IP地址的虚拟主机
[root@nginx ~]# vim /usr/local/nginx/conf/nginx.conf
[root@nginx ~]# ifconfig eth0:0 192.168.1.109/24
[root@nginx ~]# ip a
[root@nginx ~]# killall -3 nginx
[root@nginx ~]# nginx
[root@nginx ~]# netstat -anpt |grep nginx
tcp 0 0 192.168.1.109:80 0.0.0.0:* LISTEN 6670/nginx
tcp 0 0 192.168.1.108:80 0.0.0.0:* LISTEN 6670/nginx
客户机测试:
3、基于端口的虚拟主机
[root@nginx ~]# /etc/init.d/network restart
[root@nginx ~]# ip a
[root@nginx ~]# killall -3 nginx
[root@nginx ~]# nginx
[root@nginx ~]# netstat -anpt |grep nginx
tcp 0 0 192.168.1.108:8080 0.0.0.0:* LISTEN 7129/nginx
tcp 0 0 192.168.1.108:8888 0.0.0.0:* LISTEN 7129/nginx
客户机测试:
二、Nginx的访问控制
1、基于用户的访问控制
[root@nginx ~]# htpasswd -c -b /usr/local/nginx/passwd.db admin 123123
Adding password for user admin
[root@nginx ~]# cat /usr/local/nginx/passwd.db
admin:FgJf6ZoQTw/92
[root@nginx ~]# chmod 400 /usr/local/nginx/passwd.db
[root@nginx ~]# chown nginx:nginx /usr/local/nginx/passwd.db
[root@nginx ~]# ll /usr/local/nginx/passwd.db
-r-------- 1 nginx nginx 20 3月 26 17:29 /usr/local/nginx/passwd.db
[root@nginx ~]# vim /usr/local/nginx/conf/nginx.conf
[root@nginx ~]# killall -1 nginx
2、基于IP的访问控制
deny ip/ip段
allow ip/ip段
规则匹配从上往下,如匹配,则停止
[root@nginx ~]# vim /usr/local/nginx/conf/nginx.conf
[root@nginx ~]# killall -1 nginx
(客户机ip:192.168.1.104)
客户机测试:
[root@nginx ~]# vim /usr/local/nginx/conf/nginx.conf
[root@nginx ~]# killall -1 nginx
客户机再次访问: