在nginx中使用端口更改URL

时间:2017-04-28 07:36:03

标签: nginx

我正在尝试使用nginx将网址http://example.com:88/test/更改为https://example.com/test。我尝试在端口88块中使用重写,但这不起作用。

目前我使用。

    server {
       listen 88;
       server_name example.com
       return 301 https://$host$request_uri;
   }

目前http://example.com:88/test/已发送至https://example.com:88/test/

1 个答案:

答案 0 :(得分:0)

看起来没问题,“$ host”不包括端口......或者不应该。

使用“curl”或“httpie”的ouptut是什么?

$ cat /etc/nginx/sites-enabled/88_port
server {
        listen 88;
        server_name localhost;
        return 301 https://$host$request_uri;
}
$ http localhost:88/xpto
HTTP/1.1 301 Moved Permanently
Connection: keep-alive
Content-Length: 194
Content-Type: text/html
Date: Fri, 28 Apr 2017 12:32:21 GMT
Location: https://localhost/xpto
Server: nginx/1.10.0 (Ubuntu)

这似乎在1.10中工作得很好,所以除非有另一个重定向应该有效。

相关问题