基于多IP的方式
1)第一个配置文件
1 2 3 4 5 6 7 8 9 |
[root@web02 /etc/nginx/conf.d]# vim mali.conf server { listen 10.0.0.8:80; server_name localhost; location / { root /code/zhiwu; index index.html; } } |
2)第二个配置文件
1 2 3 4 5 6 7 8 9 |
[root@web02 /etc/nginx/conf.d]# vim tank.conf server { listen 172.16.1.8:80; server_name localhost; location / { root /code/tank; index index.html; } } |
3)检查配置重启
1 2 3 4 5 |
[root@web02 /etc/nginx/conf.d]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful [root@web02 /etc/nginx/conf.d]# systemctl restart nginx |
基于多端口的方式
1)第一个配置
1 2 3 4 5 6 7 8 9 |
[root@web02 /etc/nginx/conf.d]# cat mali.conf server { listen 80; server_name localhost; location / { root /code/zhiwu; index index.html; } } |
2)第二个配置
1 2 3 4 5 6 7 8 9 |
[root@web02 /etc/nginx/conf.d]# cat tank.conf server { listen 81; server_name localhost; location / { root /code/tank; index index.html; } } |
3)检查配置并重启
1 2 3 4 5 |
[root@web02 /etc/nginx/conf.d]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful [root@web02 /etc/nginx/conf.d]# systemctl restart nginx |
4)访问测试
1 2 |
1.访问 http://10.0.0.8:80 2.访问 http://10.0.0.8:81 |
基于多域名的方式
1)第一个配置
1 2 3 4 5 6 7 8 9 |
[root@web02 /etc/nginx/conf.d]# vim mali.conf server { listen 80; server_name www.mali.com; location / { root /code/zhiwu; index index.html; } } |
2)第二个配置
1 2 3 4 5 6 7 8 9 |
[root@web02 /etc/nginx/conf.d]# vim tank.conf server { listen 80; server_name www.tank.com; location / { root /code/tank; index index.html; } } |
3)检查并重启
1 2 3 4 5 |
[root@web02 /etc/nginx/conf.d]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful [root@web02 /etc/nginx/conf.d]# systemctl restart nginx |
4)配置本地hosts
1 2 3 |
C:\Windows\System32\drivers\etc\hosts 10.0.0.8 www.mali.com 10.0.0.8 www.tank.com |