Ngix對請求進行轉發,可監聽同一端口根據不同的域名轉發到不同地方,現在進行設置:
找到配置文件ngix.conf文件,進行修改:
增加要轉發到的地址:
#domain:txy.test.fang.com
upstream web_server_txy_test {
server 127.0.0.1:8081 weight=3 max_fails=2 fail_timeout=30s;
}
增加server
server {
listen 80;
server_name txy.test.fang.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://web_server_txy_test;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
break;
}
}
有多個轉發時可設置多個upstream和server,多個server可以監聽相同的端口只要轉發的地址不同就可以,其中轉發地址也可以是IIS中的地址
示例中的地址是本地地址通過域名txy.test.fang.com進行訪問時轉發到本地IIS上地址,本地IIS地址需要host文件中進行硬解
硬解域名方式,打開host文件(文件位置爲:C:\Windows\System32\drivers\etc\HOSTS),增加一行127.0.0.1 txy.test.fang.com
在服務中找到Ngix服務重新啓動,訪問http://txy.test.fang.com時就會被轉發到IIS上的http://txy.test.fang.com:8081上
如果本地硬解的域名下的功能需要在Vvisual studio中進行調試 則需要設置VS項目中的啓動項目屬性:才用本地IIS,設置項目屬性,當訪問http://txy.test.fang.com時就可以進行VS項目中的斷點進行調試了