A
A
annonimus2018-10-11 13:24:01
Nginx
annonimus, 2018-10-11 13:24:01

Why doesn't redirect from https://www to non-www https:// work?

Good day to all!
Guys, for some reason, the https redirect does not work for me on non-WWW links with subdirectories. The main domain https://www.site.com redirects to https://site.com, but for example from https://www.site.com/question/new to https:/site.com/question/new no. Yes, they are indexed by search engines. With http redirect works and goes to https.

I post nginx.conf and nginx.ssl.conf configs
server {
    listen      00.00.00.00:80;
    server_name site.com  www.site.com;
    return       301 https://site.com$request_uri;
}

server {
    listen      00.00.00.00:80;
    server_name site.com;
    error_log  /var/log/apache2/domains/site.com.error.log error;

    location / {
        proxy_pass      http://00.00.00.00:8080;
        location ~* ^.+\.(jpg|jpeg|gif|png|ico|svg|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|odt|ods|odp|odf|tar|wav|bmp|rtf|js|mp3|avi|mpeg|flv|html|htm)$ {
            root           /home/admin/web/site.com/public_html;
            access_log     /var/log/apache2/domains/site.com.log combined;
            access_log     /var/log/apache2/domains/site.com.bytes bytes;
            expires        max;
            try_files      $uri @fallback;
        }
    }

    location /error/ {
        alias   /home/admin/web/site.com/document_errors/;
    }

    location @fallback {
        proxy_pass      http://00.00.00.00:8080;
    }

    location ~ /\.ht    {return 404;}
    location ~ /\.svn/  {return 404;}
    location ~ /\.git/  {return 404;}
    location ~ /\.hg/   {return 404;}
    location ~ /\.bzr/  {return 404;}

    include /home/admin/conf/web/nginx.site.com.conf*;
}

server {
    listen      00.00.00.00:443;
    server_name site.com www.site.com;
    ssl         on;
    ssl_certificate      /home/admin/conf/web/ssl.site.com.pem;
    ssl_certificate_key  /home/admin/conf/web/ssl.site.com.key;
    error_log  /var/log/apache2/domains/site.com.error.log error;

    location / {
        proxy_pass      https://00.00.00.00:8443;
        location ~* ^.+\.(jpg|jpeg|gif|png|ico|svg|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|odt|ods|odp|odf|tar|wav|bmp|rtf|js|mp3|avi|mpeg|flv|html|htm)$ {
            root           /home/admin/web/site.com/public_html;
            access_log     /var/log/apache2/domains/site.com.log combined;
            access_log     /var/log/apache2/domains/site.com.bytes bytes;
            expires        max;
            try_files      $uri @fallback;
        }
    }

    location /error/ {
        alias   /home/admin/web/site.com/document_errors/;
    }

    location @fallback {
        proxy_pass      https://00.00.00.00:8443;
    }

    location ~ /\.ht    {return 404;}
    location ~ /\.svn/  {return 404;}
    location ~ /\.git/  {return 404;}
    location ~ /\.hg/   {return 404;}
    location ~ /\.bzr/  {return 404;}

    include /home/admin/conf/web/snginx.site.com.conf*;
}

Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
annonimus, 2018-10-13
@annonimus

I solved my problem with the following code..

server {
    listen      00.00.00.00:80;
    server_name site.com www.site.com;
if ($host ~* ^(site\.com|www\.site\.com)$ ){
  rewrite  ^/(.*)$  https://site.com/$1  permanent;
}

I posted the code in http and ssl files.
Thanks to all!

L
link7, 2018-10-11
@link7

You forgot to enter ssl certificates in your configs, this is the reason

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question