J
J
Justin Bieber2016-09-09 08:33:01
Nginx
Justin Bieber, 2016-09-09 08:33:01

Why does nginx not redirect from https://www.site.ru?

I noticed that the search engine shaval https://www.site.ru and ofigel is simple), it should be https://site.ru

Config:

server {
    listen 80;
    server_name site.ru www.site.ru;
    rewrite  ^(.*) https://$server_name$1 permanent;
}

server {
    listen   443 ssl;
    server_name www.site.ru site.ru;
    ssl_certificate     /etc/letsencrypt/live/site.ru/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/site.ru/privkey.pem;

    access_log /var/www/site.ru/logs/nginx-access.log;
    error_log /var/www/site.ru/logs/nginx-error.log;

    location / {
  proxy_pass  http://127.0.0.1:81;
  include     /etc/nginx/proxy.conf;
    }

    location ~* \.(jpg|jpeg|gif|png|ico|css|bmp|swf|js)$ {
  root /var/www/site.ru/public;
      access_log off;
      expires 10d;
    }

    location /phpmyadmin {
         root /usr/share/;
         index index.php index.html index.htm;
         location ~ ^/phpmyadmin/(.+\.php)$ {
            try_files $uri =404;
            root /usr/share/;
      proxy_pass  http://127.0.0.1:81;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include /etc/nginx/fastcgi_params;
         }

         location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
            root /usr/share/;
         }
    }

    location /phpMyAdmin {
         rewrite ^/* /phpmyadmin last;
    }

}


Help out! :(

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Slava Kryvel, 2016-09-09
@kryvel

because you have written rewrite like that

server_name site.ru www.site.ru;
rewrite  ^(.*) https://$server_name$1 permanent;

it redirects from http to https while keeping the server name,
if you want to leave rewrite, you need to change it to https:// site.ru $1
but in general, in order for everything to redirect only to https://site.ru , you need to do this
server {
    listen 80;
    server_name site.ru www.site.ru;
   return 301 https://site.ru$request_uri;
}

server {
    listen   443 ssl;
    server_name www.site.ru;
ssl_certificate     /etc/letsencrypt/live/site.ru/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/site.ru/privkey.pem;

    return 301 https://site.ru$request_uri;
}

server {
    listen   443 ssl;
    server_name site.ru;
    ssl_certificate     /etc/letsencrypt/live/site.ru/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/site.ru/privkey.pem;

    access_log /var/www/site.ru/logs/nginx-access.log;
    error_log /var/www/site.ru/logs/nginx-error.log;

    location / {
  proxy_pass  http://127.0.0.1:81;
  include     /etc/nginx/proxy.conf;
    }

    location ~* \.(jpg|jpeg|gif|png|ico|css|bmp|swf|js)$ {
  root /var/www/site.ru/public;
      access_log off;
      expires 10d;
    }

    location /phpmyadmin {
         root /usr/share/;
         index index.php index.html index.htm;
         location ~ ^/phpmyadmin/(.+\.php)$ {
            try_files $uri =404;
            root /usr/share/;
      proxy_pass  http://127.0.0.1:81;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include /etc/nginx/fastcgi_params;
         }

         location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
            root /usr/share/;
         }
    }

    location /phpMyAdmin {
         rewrite ^/* /phpmyadmin last;
    }

}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question