<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[Heck's  Blog]]></title> 
<link>https://www.heckjj.com/index.php</link> 
<description><![CDATA[一瞬间的决定，往往可以改变很多，事实上，让自己成功的往往不是知识，是精神！ 如果你总是为自己找借口，那只好让成功推迟。执行力，今天！]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[Heck's  Blog]]></copyright>
<item>
<link>https://www.heckjj.com/post//</link>
<title><![CDATA[解决nginx 反向代理时页面跳转丢失端口的问题]]></title> 
<author>Heck &lt;@hecks.tk&gt;</author>
<category><![CDATA[编程杂谈]]></category>
<pubDate>Thu, 19 Aug 2021 01:37:42 +0000</pubDate> 
<guid>https://www.heckjj.com/post//</guid> 
<description>
<![CDATA[ 
	最近公司的项目，配置nginx反向代理时遇到一个问题，当设置nginx监听80端口时转发请求没有问题。但一旦设置为监听其他端口，就一直跳转不正常；如访问欢迎页面时应该是重定向到登录页面，在这个重定向的过程中端口丢失了变默认变成80了，当然就访问不到了。<br/>&nbsp;&nbsp;&nbsp;&nbsp;这里给出一个简短的解决方案，修改nginx的配置文件。<br/>一、配置文件<br/>server &#123;<br/>listen 42112;<br/>proxy_set_header X-Real-IP $remote_addr;<br/>proxy_set_header REMOTE-HOST $remote_addr;<br/>proxy_set_header X-Forwarded-Host $host;<br/>proxy_set_header X-Forwarded-Server $host;<br/>proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br/>proxy_set_header Host $host:$server_port; #这里是重点,这样配置才不会丢失端口<br/>location / &#123;<br/>proxy_pass http://127.0.0.1:9001;<br/>&#125;<br/>location = /50x.html &#123;<br/>root html;<br/>&#125;<br/>&#125;<br/><br/>二、产生原因<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nginx没有正确的把端口信息传送到后端，没能正确的配置nginx，下面这行是关键<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;proxy_set_header Host $host:$server_port; 这一行是关键。<br/>或者<br/>proxy_set_header Host $http_host；<br/>Tags - <a href="https://www.heckjj.com/tags/nginx/" rel="tag">nginx</a> , <a href="https://www.heckjj.com/tags/%25E7%25AB%25AF%25E5%258F%25A3%25E4%25B8%25A2%25E5%25A4%25B1/" rel="tag">端口丢失</a>
]]>
</description>
</item><item>
<link>https://www.heckjj.com/post//#blogcomment</link>
<title><![CDATA[[评论] 解决nginx 反向代理时页面跳转丢失端口的问题]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>https://www.heckjj.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>