Skip to content

Instantly share code, notes, and snippets.

@andrey-helldar
Last active February 7, 2019 07:48
Show Gist options
  • Save andrey-helldar/61765e5de6b1e0650a0b57b0c2877641 to your computer and use it in GitHub Desktop.
Save andrey-helldar/61765e5de6b1e0650a0b57b0c2877641 to your computer and use it in GitHub Desktop.
Nginx redirect from www to without www (nginx редирект с www на без www)
server {
listen <your-ip>:443 ssl;
server_name www.example.com;
ssl_certificate "/var/www/httpd-cert/myuser/example.com_le1.crtca";
ssl_certificate_key "/var/www/httpd-cert/myuser/example.com_le1.key";
ssl_ciphers EECDH:+AES256:-3DES:RSA+AES:!NULL:!RC4;
ssl_prefer_server_ciphers on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
return 301 https://example.com$request_uri;
}
server {
server_name example.com;
# other rules
# другие правила для 80-го порта
return 301 https://$host:443$request_uri;
listen <your-ip>:80;
}
server {
server_name example.com;
ssl_certificate "/var/www/httpd-cert/myuser/example.com_le1.crtca";
ssl_certificate_key "/var/www/httpd-cert/myuser/example.com_le1.key";
ssl_ciphers EECDH:+AES256:-3DES:RSA+AES:!NULL:!RC4;
ssl_prefer_server_ciphers on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
add_header Strict-Transport-Security "max-age=31536000;";
ssl_dhparam /etc/ssl/certs/dhparam4096.pem;
# remove index.php from URL: example.com/index.php >> example.com
if ($request_uri ~ "/index.php"){
rewrite ^/index\.php$ /$1 redirect;
}
listen <your-ip>:443 ssl;
}
server {
listen <your-ip>:80;
server_name www.example.com;
return 301 http://example.com$request_uri;
}
server {
server_name example.com;
# other rules for 80 port
# другие правила для 80-го порта
listen <your-ip>:80;
}
@andrey-helldar
Copy link
Author

Compatible with ISPManager 5.
Совместимо с ISPManager 5.

Долгое время искал рабочий конфиг редиректов с www на без www для nginx и, наконец-то, написал нужный.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment