Wednesday, August 29, 2018

how to redirect HTTP to HTTPS on nginx

sudo vi /etc/nginx/sites-available/SITEDOMAIN

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

The first listen statement is for HTTP port of IPv4.
The second listen statement if for HTTP port of IPv6.
You can redirect from specific domain name as following:
server_name example.com www.example.com




https://www.twiceweb.net/board/view/computer/22