配置nginx虚拟主机不同端口和不同ip地址,和上编nginx基于域名配置虚拟主机博文类似,请先参考。
zxl.com域名不同端口,配置文件内容如下:
1
2
3
4
5
6
7
8
9
10
11
|
[root@zxl-nginx conf.d] # cat zxl.com.conf server { listen 81; server_name www.zxl.com zxl.com; location / { root /data/zxl ; index index.html index.htm; access_log logs /zxl .access.log; error_log logs /zxl .error.log; } } |
bbs.com域名不同端口,配置文件内容如下:
1
2
3
4
5
6
7
8
9
10
11
|
[root@zxl-nginx conf.d] # cat bbs.com.conf server { listen 82; server_name www.bbs.com bbs.com; location / { root /data/bbs ; index index.html index.htm; access_log logs /bbs .access.log; error_log logs /bbs .error.log; } } |
nginx端口查看,检测语法以及重新加载配置文件到内存中
1
2
3
4
5
6
7
8
|
[root@zxl-nginx conf.d] # netstat -nplt|grep nginx tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3476 /nginx tcp 0 0 0.0.0.0:81 0.0.0.0:* LISTEN 3476 /nginx tcp 0 0 0.0.0.0:82 0.0.0.0:* LISTEN 3476 /nginx [root@zxl-nginx conf.d] # 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@zxl-nginx conf.d] # nginx -s reload |
测试结果如下:
1
2
3
4
|
[root@zxl-nginx conf.d] # elinks http://www.zxl.com:81 --dump This is a site www.zxl.com test ! [root@zxl-nginx conf.d] # elinks http://www.bbs.com:82 --dump This is a site www.bbs.com test ! |
不同ip地址的虚拟主机配置,添加ip地址以及配置文件如下:
1
2
|
[root@zxl-nginx conf.d] # ifconfig eth0:1 192.168.33.132 [root@zxl-nginx conf.d] # ifconfig eth0:2 192.168.33.133 |
查看配置ip地址
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[root@zxl-nginx conf.d] # ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN link /loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1 /8 scope host lo inet6 ::1 /128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link /ether 00:50:56:32:9b:32 brd ff:ff:ff:ff:ff:ff inet 192.168.33.131 /24 brd 192.168.33.255 scope global eth0 inet 192.168.33.132 /24 brd 192.168.33.255 scope global secondary eth0:1 inet 192.168.33.133 /24 brd 192.168.33.255 scope global secondary eth0:2 inet6 fe80::250:56ff:fe32:9b32 /64 scope link valid_lft forever preferred_lft forever |
不同ip地址的虚拟主机配置文件如下:
ip地址192.168.33.132配置文件内容
1
2
3
4
5
6
7
8
9
10
11
|
[root@zxl-nginx conf.d] # cat zxl.com.conf server { listen 192.168.33.132:80; server_name www.zxl.com zxl.com; location / { root /data/zxl ; index index.html index.htm; access_log logs /zxl .access.log; error_log logs /zxl .error.log; } } |
ip地址192.168.33.133配置文件内容
1
2
3
4
5
6
7
8
9
10
11
|
[root@zxl-nginx conf.d] # cat bbs.com.conf server { listen 192.168.33.133:80; server_name www.bbs.com bbs.com; location / { root /data/bbs ; index index.html index.htm; access_log logs /bbs .access.log; error_log logs /bbs .error.log; } } |
检测nginx配置文件以及重新加载nginx
1
2
3
4
|
[root@zxl-nginx conf.d] # 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@zxl-nginx conf.d] # nginx -s reload |
1
2
3
4
5
|
测试结果如下: [root@zxl-nginx conf.d] # elinks http://192.168.33.132 --dump #This is a site www.zxl.com test! This is a site 192.168.33.132 test! [root@zxl-nginx conf.d] # elinks http://192.168.33.133 --dump #This is a site www.bbs.com test! This is a site 192.168.33.133 test! |
本文转载自:http://noodle.blog.51cto.com/2925423/1726416