nginx_非標准端口_同端口_http_自動跳轉_https


nginx_非標准端口_同端口_http_自動跳轉_https

轉載注明來源: 本文鏈接 來自osnosn的博客,寫於 2021-02-05.

參考

背景

如果網站架設在標准端口。可以通過設置 http 強制跳轉到 https。即,從80口跳轉到443口。完成加密網站的跳轉。

把 https 的網站設置在非標准端口。訪問的時候需要帶上端口號。
總是因為忘了打上 https:// 前綴導致訪問失敗。
希望在沒打https://前綴時,都能正常訪問。

文檔

相同端口 http 跳 https

默認497錯誤,是返回400 Bad Request: The plain HTTP request was sent to HTTPS port
可以修改這個錯誤處理。 在 server { .. } 中加入一行。

  • error_page 497 https://$host$request_uri; 默認用302,臨時重定向
  • error_page 497 =301 https://$host$request_uri; 永久重定向
  • error_page 497 =307 https://$host$request_uri; 臨時重定向,不改變請求的方法(如post還是post)

如果重定向后,沒有帶上正確的端口號,則顯式的加上端口號 $server_port

  • error_page 497 https://$host:$server_port$request_uri;

還有一種寫法,

  • error_page 497 https://$host:$server_port$uri$is_args$args;

轉載注明來源: 本文鏈接 來自osnosn的博客.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM