【问题标题】:Change url with port in nginx在nginx中使用端口更改url
【发布时间】:2017-04-28 07:36:02
【问题描述】:

我正在尝试使用 nginx 将 URL 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/

【问题讨论】:

  • 来自nginx $host in this order of precedence: host name from the request line, or host name from the “Host” request header field, or the server name matching a request

标签: nginx


【解决方案1】:

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

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

$ 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 中工作得很好,所以除非有另一个应该工作的重定向。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-30
    • 2022-11-16
    • 2018-05-02
    • 2020-01-15
    • 2014-08-27
    • 1970-01-01
    • 2016-03-31
    • 2014-09-19
    相关资源
    最近更新 更多