nginx转发携带端口
时间: 2023-08-28 08:22:26 浏览: 108
要在Nginx转发中携带端口信息,你可以使用proxy_set_header指令来设置请求头。在你的Nginx配置文件中找到相应的server块,并在其中添加以下代码段:
```
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8080;
}
```
这样配置后,Nginx会将请求头中的Host、X-Real-IP和X-Forwarded-For字段设置为相应的值,并将请求转发到本地的8080端口。这样,你就可以实现端口转发,并携带端口信息。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [关于nginx进行端口转发的实现浅谈](https://blog.csdn.net/weixin_45707610/article/details/131129958)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [Nginx 实现端口转发](https://blog.csdn.net/ikkkp/article/details/129408520)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文