1

I am trying to configure nginx with php-fpm (php v 5.3.5) on ubuntu 11. Both nginx and php5-fpm are set to run as www-data. nginx appears to serve html files but php files are not being served (log files generate a 404 error). php5-fpm is running and listening on the same port that nginx is attempting to connect on (9000). Config files are copied below. Files are located in /var/www (www-data has read/write access to all files within that directory).

How can I go about troubleshooting this issue in order to figure out whether php5-fpm is even properly receiving the request from nginx and whether it is unable to process the request because of incorrect privileges/incorrect config file location.

Any help would be appreciated.

nginx.conf file:

 user www-data; worker_processes 4; pid /var/run/nginx.pid; events { worker_connections 768; } http { include mime.types; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; # server_tokens off; server_names_hash_bucket_size 64; # server_name_in_redirect off; include /etc/nginx/mime.types; default_type application/octet-stream; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; gzip on; gzip_disable "msie6"; gzip_comp_level 2; gzip_proxied any; gzip_http_version 1.1; gzip_buffers 16 8k; gzip_types text/plain text/css text/javascript application/json application/x-javascript text/xml application/xml application/xml+rss; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; } 

default file in sites (enabled/available) folder:

default server { listen 80; server_name localhost; access_log /var/log/nginx/localhost.access.log; location / { root /var/www; index index.html index.php; try_files $uri $uri/ /index.php?q=$uri&$args; } location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ { access_log off; expires 30d; root /var/www; } ## Disable viewing .htaccess & .htpassword location ~ /\.ht { deny all; } include php.conf; } 

php.config file in nginx directory:

fastcgi_intercept_errors on; location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; 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 SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT /var/www; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx; 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; fastcgi_read_timeout 600; # Set fairly high for debugging fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; } 

log file output for php5-fpm:

configuration file /etc/php5/fpm/main.conf test is successful 

log file output from nginx:

"GET /index.php HTTP/1.1" 404 31 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.220 Safari/535.1" 

2 Answers 2

1

aTo answer the original question. In you vhost configuration a part is missing, telling nginx what to do with the PHP files.

Example:

location ~ \.php$ { include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME PATH_TO_YOUR_WEBSITE_ROOT$fastcgi_script_name; } 

You could also look at https://www.digitalocean.com/community/articles/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-12-04 and if you plan to run multiple vhosts https://www.digitalocean.com/community/tutorials/how-to-optimize-nginx-with-php-pools-on-an-ubuntu-13-04-vps Both tutorials show in a good way how to setup everything.

Sign up to request clarification or add additional context in comments.

Comments

1

You're missing a bit in your server block that is meant to pass php files over php5-fpm.

e.g.

location ~ .php$ { include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name; } 

To write a new server block (the bit in /site-enabled), try using this tool.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.