---
title: "nginx的坑：带端口号的自动跳转（备忘）"
author: "iyuan"
date: "2017-08-08T15:14:12Z"
tags: []
categories: ["开源软件"]
slug: "nginx"
draft: false
lastmod: "2017-08-08T15:14:12Z"
id: 2388684
url: "https://iyuan.iteye.com/blog/2388684"
---

问题描述：

nginx 反向代理时，请求url 没有带尾部／会出现意外跳转，nginx默认会重定向到带尾部/的location/path

这里的坑是：如果server带了listen port , 自动跳转会带上这个port, 万一前面还有一层反向代理，就出现意外了。

解法：
1. 前层反向代理是域名等不带端口号的字段，直接配置 port_in_redirect off

2. 前层反向代理是另外一个端口，这个比较尴尬，需要配置 proxy_pass ，手动重定向

```java

location = /xx/ {}
location = /xx {proxy_pass: http://{yours} }

```