Redirect HTTP to HTTPS in Nginx

Since my server do not serve http, so need to redirect http to https

simply modify /etc/nginx/nginx.conf

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

and then run

#systemctl restart nginx

now you can connect to http and it will be redirect to https to access the site.

Leave a Reply