Why not work with redirect https://www without www for https://?

Good time of day!
Guys, I have some reason does not work redirect from https without WWW URLs with subdirectories. The primary domain https://www.site.com will redirected on https://site.com, but for example with https://www.site.com/question/new on https:/site.com/question/new anymore. Yes, they are indexed by search engines. Http redirect is working and switches to https.
post the configs of nginx.conf and nginx.ssl.conf
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!
March 12th 20 at 08:41
2 answers
March 12th 20 at 08:43
Solution
All matter is decided 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;
}

Code is placed in the http and ssl files.
Thank you all!
March 12th 20 at 08:45
You forgot to enter in their configs ssl certificates, that's the reason
And be a little more in detail. )
Thank you. - Dwight_Senger commented on March 12th 20 at 08:48
I should add, but still something..

server {
listen 00.00.00.00:80;
ssl on;
ssl_certificate /home/admin/conf/web/ssl.site.com.crt;
ssl_certificate_key /home/admin/conf/web/ssl.site.com.key;
server_name site.com; - Dwight_Senger commented on March 12th 20 at 08:51
server {
listen 80;
server_name example.com;
return 301 http://www.example.com$request_uri;
}

server {
listen 80;
server_name www.example.com;
# rest of server config
} - Keely35 commented on March 12th 20 at 08:54
@Keely35,

In nginx.conf I left only this..
server {
server_name "~^www\.(.*)$" ;
return 301 $scheme://$1$request_uri ;
}

and nginx.ssl.conf currently looks like this.
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.crt;
# 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 <a href="https://00.00.00.00:8443;">https://00.00.00.00:8443;</a>
 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 <a href="https://00.00.00.00:8443;">https://00.00.00.00:8443;</a>
}

 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*;
}



But still the redirection is not working.
Thank you! - Dwight_Senger commented on March 12th 20 at 08:57

Find more questions by tags Nginx