Welcome! Log In Create A New Profile

Advanced

php_fpm, chroot and try_files

Posted by maverick78 
php_fpm, chroot and try_files
March 21, 2012 09:27AM
Hello!

I configured php-fpm to use build-in chroot.

Everything works fine, but there ist a problem when I try to check if a php-file exists.

server {
location ~ \.php$ {
root /public;
try_files $uri =404;
}
}

In this case, I alsways get 404 not fount for php-files.

When I comment out try_files, the php-files are processed.

Is there a way of proper configuration in this case? How can I check if an php-file really exists before I pass it to php-fpm?



Edited 1 time(s). Last edit at 03/21/2012 09:28AM by maverick78.
Re: php_fpm, chroot and try_files
March 27, 2012 04:40AM
For what I can see your try_files line is redundant since this would simply return a 404 http status code if the file in the URI doesn't exist and that is just default behaviour. It might even be erroneous since try_files needs a list of files to try - I use like "try_files $uri $uri/ /index.php?q=$request_uri;"
If I were you I'd remove the try_files line completely and enable debug logging with "error_log /path/to/log debug;"
And the obvious thing here is that you need to forward php processing to the php-fpm processes.

Here's one of our standard configs for Joomla:

server {
server_name example.com;
access_log /var/log/nginx/example.com.log main;
error_log /var/log/nginx/example.com.err;
root /www/example.com/current;
location / { try_files $uri $uri/ /index.php?q=$request_uri; }
location ~ \.php$ { include fastcgi_params+; }
}

And the fastcgi_params+ looks like the following (it's just a copy of fastcgi_params with last 5 lines added):

fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;

fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;

fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;

fastcgi_buffer_size 512k;
fastcgi_buffers 8 512k;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 244
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready