Answer the question
In order to leave comments, you need to log in
nginx. How to use different php for different location?
There is NGINX used as a web server for example.com/site1 and as a reverse proxy for example.com/site2.
How to use the "built-in" php-fpm for site1, and proxy requests to site2?
I am attaching a conditional example of a part of the config.
location /site1 {
root /var/www/site1/;
}
location /site2/ {
proxy_pass https://site2/;
}
location ~* \.php$ {
try_files $uri = 404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock; # подключаем сокет php-fpm
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
Answer the question
In order to leave comments, you need to log in
nginx.org/ru/docs/http/ngx_http_core_module.html#l...
If the matched prefix location of the maximum length has the “^~” modifier, then the regular expressions are not checked.
location /site2/
add And add ^~
location /site1 {
location ~* \.php$
location /site1 {
root /var/www/site1;
location ~* \.php$ {
try_files $uri = 404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock; # подключаем сокет php-fpm
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
location ^~ /site2/ {
proxy_pass https://site2/;
}
I suspect you need to elevate the location /site2/ block above the location ~* \.php$ block in the file.
They go in order of coincidence, if your php-fpm block is higher - all php, regardless of what is described below, goes to it
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question