Force www. and https in nginx.conf (SSL)

前端 未结 4 1140
梦谈多话
梦谈多话 2021-02-05 20:48

After purchasing a SSL certificate I have been trying to force all pages to secured https and to www.

https://www.exampl.com is working and secure but only if type it i

4条回答
  •  南方客
    南方客 (楼主)
    2021-02-05 21:16

    I searched a lot , finally this is my right answer. also remember to add a www A record in your domain registar's dns control panel.

     # Force all users to https://www.example.com
    server {
        listen 80;
        server_name example.com www.example.com;
        return 301 https://www.example.com$request_uri;
    }
    server {
        listen 443 ssl;
        server_name example.com;
        ssl_certificate /etc/nginx/ssl/www.example.com.pem;
        ssl_certificate_key /etc/nginx/ssl/www.example.com.key;
        return 301 https://www.example.com$request_uri;
    }
    server {
        listen 443 ssl;
        server_name www.example.com;
        root /var/www/html
    
        error_page  403 /error/404.html;
        error_page  404 /error/404.html;
        error_page  500 502 503 504 /error/50x.html;
        ssl_certificate /etc/nginx/ssl/www.example.com.pem;
        ssl_certificate_key /etc/nginx/ssl/www.example.com.key;
    }
    

提交回复
热议问题