S
S
Sergey Brovko2021-06-25 18:45:19
Nginx
Sergey Brovko, 2021-06-25 18:45:19

Why is the nginx rule not working?

Hello. Either I'm already melting from the heat or it really doesn't work.

server { 
        server_name  example.com www.example.com;
        listen 443 ssl http2;
        ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;    
        charset off;
        index index.php index.html;
        access_log /home/example/example.com/logs/access.nginx.log;
        error_log /home/example/example.com/logs/error.nginx.log notice;

        root /home/example/example.com/www/public;

        location ^~ /static {      
            root /home/example/example.com/app;       
        }
       
        location / {
            include /etc/nginx/auth.conf;
            try_files $uri $uri/ /index.php$is_args$args;
            include /etc/nginx/include/example.com.con[f];
        }
        
        location ~ \.php$ {
            fastcgi_pass   unix:/var/run/example.com.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    
        location ~ ^/assets/.*\.php$ {
            deny all;
        }
        location ~* /\. {
            deny all;
        }  
}

There is such a config. One of the frameworks (laravel) lives there in public.

I want the urls /thing (and everything below them (/thing/any/thing)) to be opened from a separate root,
i.e. everything that is NOT /thing* - from the main root, but /thing* from a separate directory (let it be app (located at the www level)). The content of /thing* is plain static (with index.html, there is a reactive SPA).

I do something like this:
server { 
        server_name  example.com www.example.com;
        listen 443 ssl http2;
        ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;    
        charset off;
        index index.php index.html;
        access_log /home/example/example.com/logs/access.nginx.log;
        error_log /home/example/example.com/logs/error.nginx.log notice;

        root /home/example/example.com/www/public;

        location /thing {      
            alias /home/example/example.com/app;
            try_files $uri $uri/ /index.html$is_args$args;         
        }

        location ^~ /static {      
            root /home/example/example.com/app;       
        }
       
        location / {
            include /etc/nginx/auth.conf;
            try_files $uri $uri/ /index.php$is_args$args;
            include /etc/nginx/include/example.com.con[f];
        }
        
        location ~ \.php$ {
            fastcgi_pass   unix:/var/run/example.com.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    
        location ~ ^/assets/.*\.php$ {
            deny all;
        }
        location ~* /\. {
            deny all;
        }  
}


/thing and /thing/ starts working for me, but everything below /thing/something does not work. Though like the similar config quietly works.
I ask for help

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2021-06-25
@cyber01

try_files $uri $uri/ /index.html$is_args$args;

Change to
try_files $uri $uri/ /index.html =404;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question