1、复制Nginx配置文件
[root@localhost ~]# cd /etc/nginx/conf.d/
[root@localhost conf.d]# cp default.conf default1.conf
2、修改配置文件 default.conf(修改端口为80,路径为 /opt/app/code)(这里只贴出部分需要修改的配置信息,剩余配置信息不变)
[root@localhost conf.d]# vim default.conf
server {
listen 80; #设置端口号为80(默认是80)
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /opt/app/code; #访问页面的路径
index index.html index.htm;
}
3、修改配置文件 default1.conf (修改端口为81,路径为 /opt/app/code1,区别于80端口的配置信息)(这里只贴出部分需要修改的配置信息,剩余配置信息不变)
[root@localhost conf.d]# vim default1.conf
server {
listen 81; #设置端口号为81
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /opt/app/code1; #设置访问路径
index index.html index.htm;
}
4、创建 default.conf 对应路径下的html文件
[root@localhost conf.d]# mkdir /opt/app/code
[root@localhost conf.d]# cd /opt/app/code
[root@localhost code]# vim admin.html
<html>
<head>
<meta charset="utf-8">
<title>vincen</title>
</head>
<h1>nginx 80端口</h1>
<h1>基于端口虚拟主机</h1>
</html>
5、创建 default1.conf对应路径下的html文件
[root@localhost code]# mkdir /opt/app/code1
[root@localhost code]# cd /opt/app/code1
[root@localhost code1]# vim admin1.html
<html>
<head>
<meta charset="utf-8">
<title>wen</title>
</head>
<h1>nginx 81端口</h1>
<h1>基于端口虚拟主机</h1>
</html>
6、检查Nginx的配置语法
[root@localhost code1]# nginx -tc /etc/nginx/nginx.conf
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
7、重新载入Nginx服务
[root@localhost code1]# nginx -s reload -c /etc/nginx/nginx.conf
8、浏览器访问
访问80端口
访问81端口