V
V
Valentin Melnik2021-10-16 21:33:02
Nginx
Valentin Melnik, 2021-10-16 21:33:02

How to get rid of 404 error on yii and nginx site after page refresh?

There is a site sub1.site.com on yii on a webserver with nginx.
Frontend nginx config is like this

server {
    listen 80;
    listen 443 ssl;

    set $host_path "/opt/www/fe.sub1.site.com/build";
    access_log  /var/log/nginx/sub1.access.log up_log;
    error_log   /var/log/nginx/sub1.ua.error.log;
    server_name  sub1.site.com;
    root   $host_path;
    chunked_transfer_encoding off;
    charset utf-8;

    location /.well-known {
        root /opt/www;
    }
 error_page  405     =200 $uri;
 
    location / {
        try_files $uri @back;
    }

    location @back {
        proxy_pass http://127.0.0.1:8080$request_uri;
    }

server {
    listen 1280;

    server_name  fe.site.com;

    location / {
        return 301 https://$host$request_uri;
    }

    location /.well-known {
        root /opt/www;
    }
}


Placed on the same server another site (a clone of the first one with minor changes)
sub2.site.com

server {
    listen 80;
    listen 443 ssl;

    set $host_path "/opt/www/fe.sub2.site.com/build";
    access_log  /var/log/nginx/sub2.access.log up_log;
    error_log   /var/log/nginx/sub2.ua.error.log;
    server_name  sub2.site.com;
    root   $host_path;
    chunked_transfer_encoding off;
    charset utf-8;

    location /.well-known {
        root /opt/www;
    }
 error_page  405     =200 $uri;
 
#   location / {
#        try_files $uri @back;
#    }

#    location @back {
#        proxy_pass http://127.0.0.1:8080$request_uri;
#    }

#server {
#    listen 1280;
#    server_name  fe.site.com;
#    location / {
#        return 301 https://$host$request_uri;
#    }
#    location /.well-known {
#        root /opt/www;
#    }
#}

The problem is that if the block (below) is commented out on the second site, then when updating the site on any page sub2.site.com/page we get a 404 error, but if the address is sub2.site.com, then there are no problems with reloading the page
#   location / {
#        try_files $uri @back;
#    }

#    location @back {
#        proxy_pass http://127.0.0.1:8080$request_uri;
#    }


If this block is uncommented, then the site sub1.site.com is loaded at the address sub2.site.com Please tell me

how to fix the 404 error of the second site?

And another question is how to find out why the block with listen 1280;? The site sub1.site.com does not work without it, but it is commented out in sub2. If 1280 on sub2 is uncommented, then nothing changes for it.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question