nginx設置http 301重定向到https


  今天有位客戶問ytkah在nginx服務器如何設置http 301重定向到https,其實不難。他的服務器安裝寶塔面板了,更好操作了。進入站點設置的配置文件,如下圖所示,在第11行左右加入跳轉代碼  

    #301-START
    if ($host ~ '^abc.com'){
	  return 301 https://www.abc.com/$request_uri;
	}
	#301-END
	#301-START
  	if ( $scheme = http ){
          return 301 https://$server_name$request_uri;
          #或return 301 https://www.abc.com/$request_uri;
        } 
        #301-END

  

 

 另外一種方法是直接在nginx配置文件里改,一般是在會在 /usr/local/nginx/conf/nginx.conf

server {
    listen 80;
    ...
    return 301 https://$server_name$request_uri;
}

server {
    listen 443;
    ...
}

  


免責聲明!

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



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