Nginx Redirect HTTP to HTTPS automatically

前端 未结 1 1934
心在旅途
心在旅途 2021-01-25 07:31

I am trying to redirect all my traffic from http to https automatically. How can i do a 301 redirect to all my domain and subdomains?

This is N

相关标签:
1条回答
  • 2021-01-25 07:47

    The default server will accept http connections for any server name (without an explicit server block). Use the $host variable to determine the name of the requested domain.

    server {
        listen 80 default_server;
        listen [::]:80 default_server;
        return 301 https://$host$request_uri;
    }
    

    See this document for more.

    0 讨论(0)
提交回复
热议问题