使用nginx服务器,实现同一IP同一端口访问不同项目,以域名区分所访问项目

这里我使用了两台nginx服务器,一台服务器将不同项目绑定到不同端口,一台服务器将不同域名分发到不同端口的项目上。

第一台nginx的conf文件server部分:

server {
        listen       8000;
        server_name  localhost;
        root   E:/test/pro1;
        location / {
           index    index.html index.htm;  
        }
    }


    server {
        listen       8001;
        server_name  localhost;
        root   E:/test/pro2;
        location / {
          index    index.html index.htm;   
        }
    }
第二台nginx的conf文件的server部分:

server {
        listen       80;
        server_name  www.testpro01.com testpro01.com;
        location / {
           proxy_pass    http://127.0.0.1:8000;
        }
    }


    server {
        listen       80;
        server_name  www.testpro02.com testpro02.com;
        location / {
          proxy_pass    http://127.0.0.1:8001/;
        }
    }

最后用bat文件用以对两个nginx服务器进行操作

启动文件如下:start.bat

@echo off
echo [start...]
cd /d E:
cd spiovnet\nginx-1.16.1
call start nginx.exe
cd /d D:
cd nginx-1.16.1
call start nginx.exe
echo [end...]
@pause

其他的雷同,只是命令不一样

nginx启动命令:start nginx.exe 或者 nginx

nginx重新加载配置命令:nginx -s reload

ngin重启命令:nginx -s reopen

ngin关闭命令:nginx -s stop

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值