Answer the question
In order to leave comments, you need to log in
How not to duplicate php-fpm settings in each location?
Good afternoon.
All PHP files should go to PHP-FPM, but for some files and directories, some individual parameters may change, for example, fastcgi_read_timeout. Now for each location you have to duplicate the same code:
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php5-fpm.sock;
server {
listen 80 default_server;
root /var/www/site.ru/www;
index index.php;
server_name site.ru;
access_log /var/www/site.ru/log/nginx.access.log;
error_log /var/www/site.ru/log/nginx.error.log;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
location = /task.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_read_timeout 300;
}
location ~ /cron/.+\.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_read_timeout 600;
}
}
Answer the question
In order to leave comments, you need to log in
Understood my issue. Maybe someone will come in handy.
1. Use named location
location / {
try_files $uri $uri/ =404;
}
# именованный location
location @php {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
location ~ \.php$ {
try_files /no @php;
}
location = /task.php$ {
try_files /no @php;
fastcgi_read_timeout 300; # не сработает
}
location ~ /cron/.+\.php$ {
try_files /no @php;
fastcgi_read_timeout 600; # не сработает
}
# /etc/nginx/php.conf
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php5-fpm.sock;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include /etc/nginx/php.conf;
}
location = /task.php$ {
include /etc/nginx/php.conf;
fastcgi_read_timeout 300; # сработает
}
location ~ /cron/.+\.php$ {
include /etc/nginx/php.conf;
fastcgi_read_timeout 600; # сработает
}
include, as it were, hints that you can insert pieces of configs from separate files. You create a file with what you need and just write include my-awsome-config-file.
Install centminmod on the test server, see how it works ;) Inclusions in fact, as mentioned above.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question