Last active
February 7, 2019 07:48
-
-
Save andrey-helldar/61765e5de6b1e0650a0b57b0c2877641 to your computer and use it in GitHub Desktop.
Nginx redirect from www to without www (nginx редирект с www на без www)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compatible with ISPManager 5.
Совместимо с ISPManager 5.
Долгое время искал рабочий конфиг редиректов с www на без www для nginx и, наконец-то, написал нужный.