这里我使用了两台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