1.配置多端口的虚拟主机
[root@web01 conf.d]# vim port.conf
server {
listen 81;
location / {
root /code_81;
index index.html;
}
}
server {
listen 82;
location / {
root /code_82;
index index.html;
}
}
2.根据配置文件创建所需的目录
[root@web01 conf.d]# mkdir /code_8{1..2}
[root@web01 conf.d]# echo "81" > /code_81/index.html
[root@web01 conf.d]# echo "82" > /code_82/index.html
3.检查语法并重启服务
[root@web01 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@web01 conf.d]# systemctl restart nginx
4.如何去访问
http://10.0.0.7:82/