查看: 82|回覆: 0

nginx配置域名代理后访问域名又自动切换回IP

[複製鏈接]

0

主題

0

回帖

0

積分

热心网友

金币
0
閲讀權限
220
精華
0
威望
0
贡献
0
在線時間
0 小時
註冊時間
2008-1-16
發表於 2020-8-20 10:28:00 | 顯示全部樓層 |閲讀模式

nginx初始配置为

location ^~ /lucas/ {
  proxy_pass http://xxxx:8080/lucas/;
 }

把配置加多几行参数,解决访问域名又自动切换回IP

location ^~ /lucas/ {
  proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   Host      $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_redirect off;
        proxy_pass http://xxxx:8080/lucas/;
 }

 

Windows本地测试:

1、C:\Windows\System32\drivers\etc 目录下在hosts文件里面加多一行,在本机可以通过域名访问本机。

127.0.0.1       xxxx.com

2、下载nginx:http://nginx.org/

3、解压nginx

4、修改conf\nginx.conf文件,修改server_name为域名,添加多一个代理

server {
        listen       80;
        server_name  xxxx.com;

location ^~ /lucas/ {
  proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   Host      $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_redirect off;
  proxy_pass http://xxxx:8080/lucas/;
 }

。。。。。。
}

5、nginx.exe目录下打开cmd,执行命令打开nginx

6、在本机浏览器访问:http://xxxx.com/lucas/

start nginx : 启动nginx
nginx -s reload :修改配置后重新加载生效
nginx -s reopen :重新打开日志文件
nginx -t -c /path/to/nginx.conf 测试nginx配置文件是否正确

nginx -t                         # 查看nginx状态

 

关闭nginx:
nginx -s stop :快速停止nginx
nginx -s quit :完整有序的停止nginx

 

 更多nginx知识可参考:https://www.cnblogs.com/loong-hon/p/9060515.html

 



来源:https://www.cnblogs.com/RealWorld/p/13533643.html
回覆

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即注册

本版積分規則

相关侵权、举报、投诉及建议等,请发 E-mail:qiongdian@foxmail.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部