A
A
Artyom2020-11-18 06:43:36
Nginx
Artyom, 2020-11-18 06:43:36

nginx. How to redirect the request to php in the absence of a file?

Hello.

Can you please tell me how to make in nginx so that requests for getting statics, in case of its absence, are redirected to a php script?

My config:

server {
    location / {
        location ~ [^/]\.ph(p\d*|tml)$ {
            try_files /does_not_exists @php;
        }
        
        location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ {
            expires 30d;
        }
        
        try_files $uri $uri/ /index.php?$query_string;
    }
    
    location @php {
        # fastcgi directives
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Taran, 2020-11-18
@Nexus94

via error_page

error_page 401 403 404 405 500 502 503 = @fallback;
        location @fallback {
                proxy_pass              http://127.0.0.1:82;
                proxy_set_header        Host            $host;
                proxy_set_header        X-Real-IP       $remote_addr;
                proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;

                }

try_files accordingly, you can remove
the config given for nginx + apache

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question