The best way to force http request redirect to https in nginx

Use 301 redirect.
 
    server {
        listen  80;
        server_name blog.errong.win;
        return 301 https://$server_name$request_uri;
    }

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

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

    server {
        listen       443 ssl;

        ssl_certificate      /etc/letsencrypt/live/errong.win/fullchain.pem;
        ssl_certificate_key  /etc/letsencrypt/live/errong.win/privkey.pem;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

        server_name  ~^(.+)?\.errong\.win$;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   vhosts/$1;
            index  index.html index.htm;
        }
   } 
 
Remember reload your nginx server 
sudo sbin/nginx -s reload 

You can check with developer tool:
 

Comments

Popular posts from this blog

How to fix error : no module named sendgrid when try to use sendgrid python lib in PHP.

react-native run-android : sun.security.provider.cert path.SunCertPathBuilderException : unable to find valid certification path to req uested target

react-native run-android : do not build/update modified code(App.js)