Answer the question
In order to leave comments, you need to log in
Forced removal of www from a link (Nginx, HTTPS, Passenger)?
I googled half of the Internet and unfortunately did not find a working solution.
The server runs a Rails application under Passenger (which runs on Nginx). In addition to all this, the site has a forced redirect to the https version of the site.
Redirecting to the https version of the site is as follows:
server {<br>
listen 80;<br>
rewrite ^(.*) https://example.ru$1 permanent;<br>
}<br>
server {<br>
listen 443;<br>
server_name example.ru;<br>
#rewrite ^ https://$server_name$request_uri? permanent;<br>
<br>
ssl on;<br>
ssl_certificate /opt/nginx/conf/certs/example.ru.crt;<br>
ssl_certificate_key /opt/nginx/conf/certs/example.ru.key.nopass;<br>
<br>
charset utf-8;<br>
root /var/www/public;<br>
passenger_enabled on;<br>
rails_env production;<br>
<br>
error_page 500 502 503 504 /50x.html;<br>
location = /50x.html {<br>
root html;<br>
}<br>
}<br>
Answer the question
In order to leave comments, you need to log in
And server_name in that block is not specified at all? It should be:
server {
listen 80;
server_name example.com www.example.com;
rewrite ^(.*) https://example.com$1 permanent;
}
server {
listen 80;
server_name www.example.com;
location ~ (?<URL>^.*) {
return 301 https://example.com$url$is_args$args;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question