301 redirect to nginx conf code example
Example 1: How to redirect a request from http to https using nginx
server {
listen 80 default_server;
server_name _;
return 301 https://$host$request_uri;
}
Example 2: nginx redirect www to non-www
server {
server_name www.example.com;
return 301 $scheme://example.com$request_uri;
}