1、复制Nginx配置文件

[[email protected] ~]# cd /etc/nginx/conf.d/
[[email protected] conf.d]# cp default.conf default1.conf 

2、修改配置文件 default.conf(修改端口为80,路径为 /opt/app/code)(这里只贴出部分需要修改的配置信息,剩余配置信息不变

[[email protected] 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端口的配置信息)(这里只贴出部分需要修改的配置信息,剩余配置信息不变

[[email protected] 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文件

[[email protected] conf.d]# mkdir /opt/app/code
[[email protected] conf.d]# cd /opt/app/code
[[email protected] code]# vim admin.html
<html>
<head>
        <meta charset="utf-8">
        <title>vincen</title>
</head>
<body style="backgroup-color:yellow;">
<h1>nginx 80端口</h1>
<h1>基于端口虚拟主机</h1>
</body>
</html>

5、创建 default1.conf对应路径下的html文件

[[email protected] code]# mkdir /opt/app/code1
[[email protected] code]# cd /opt/app/code1
[[email protected] code1]# vim admin1.html
<html>
<head>
	<meta charset="utf-8">
	<title>wen</title>
</head>
<body style="backgroup-color:yellow;">
<h1>nginx 81端口</h1>
<h1>基于端口虚拟主机</h1>
</body>
</html>

6、检查Nginx的配置语法

[[email protected] 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服务

[[email protected] code1]# nginx -s reload -c /etc/nginx/nginx.conf

8、浏览器访问

     访问80端口

Nginx基于端口虚拟主机

     访问81端口

Nginx基于端口虚拟主机 

相关文章: