How to setup nginx to make php works in site subdirectories
Max
nginxyz at mail.ru
Sun Feb 12 12:53:10 UTC 2012
12 февраля 2012, 15:00 от Dmitry Timoshenko <dimentiy2k at gmail.com>:
> Hello,
>
> I'm nuewbie in nginx, I've installed and setup nginx & php,
> everything is fine except .php files located in site's subdirectories
> are not processed at all.
>
> i.e. example.com/download.php works fine, but
> example.com/stuff/dosomething.php is sent to client as plain text.
>
> Please, would any kind soul tell me what should I change to resolve the
> problem.
> Thank you.
>
> I use those settings.
>
> #
> # example.com
> #
>
> server {
> listen 80;
> server_name example.com;
>
> access_log /var/log/nginx/example.com.access.log;
>
> location / {
> root /var/www/nginx-default/example.com;
> index index.html index.htm index.php;
> }
>
> ## Parse all .php file in the /var/www directory
> location ~ .php$ {
> fastcgi_split_path_info ^(.+\.php)(.*)$;
> fastcgi_pass backend;
> fastcgi_index index.php;
> fastcgi_param SCRIPT_FILENAME
> /var/www/nginx-default/example.com$fastcgi_script_name;
> include fastcgi_params;
> 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_intercept_errors on;
> fastcgi_ignore_client_abort off;
> fastcgi_connect_timeout 60;
> fastcgi_send_timeout 180;
> fastcgi_read_timeout 180;
> fastcgi_buffer_size 128k;
> fastcgi_buffers 4 256k;
> fastcgi_busy_buffers_size 256k;
> fastcgi_temp_file_write_size 256k;
> }
>
> ## Disable viewing .htaccess & .htpassword
> location ~ /\.ht {
> deny all;
> }
> }
>
> upstream backend {
> server 127.0.0.1:9000;
> }
That isn't your complete configuration now, is it? Another
location block (which you haven't posted) seems to be
matching your subdirectory requests. Add this to your
server config and then check your error log to see what's
matching your requests - look for log entries that look
like "using configuration" to find the matching location
block.
error_log /var/log/nginx/example.com.error.log debug;
root /var/www/nginx-default/example.com;
Always set the root directory inside the server configuration
block, otherwise it will be reset to the --prefix configuration
argument that nginx was compiled with (run "nginx -V"
to find out yours).
Max
More information about the nginx
mailing list