nginx staging 將 http 改寫為帶有連接埠號碼的 https

nginx staging 將 http 改寫為帶有連接埠號碼的 https

我收到 400 錯誤請求。

這是配置代碼。文件:staging.rewrites

if ($scheme = http) {
   return 301 https://$host:[port]$request_uri;
}

有誰知道這是否是有效的重寫?

答案1

我不知道你的設定檔在哪裡,但我寧願在 80 連接埠中使用以下行來重寫對連接埠 443 的請求:

server {
    listen 80;

    server_name YOURSERVER_DOMAIN;

    access_log /var/log/nginx/access.http.log detailed;
    error_log /var/log/nginx/error.http.log notice;

    location / {
        rewrite ^ https://$host$request_uri? permanent;
    }
}

問候

答案2

這是在 nginx 中執行 http -> https 重定向的首選方法:

server {
    server_name example.com;

    return 301 https://www.example.com$request_uri;
}

相關內容