查看: 144|回复: 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:[email protected]

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

在本版发帖返回顶部