Can't get php-fpm with Nginx to work

Sudheer asked:

Server: CentOs x86_64


listen =
listen.allowed_clients =
user = webuser1
group = webuser1

pm = dynamic
pm.max_children = 15
pm.start_servers = 3
pm.min_spare_servers = 1
pm.max_spare_servers = 5
pm.max_requests = 2000

request_slowlog_timeout = 5
slowlog = /home/webuser1/tmp/logs/webuser1.slow.log

php_admin_value[error_log] = /home/webuser1/tmp/logs/webuser1.error.log
php_admin_flag[log_errors] = on


server {
listen       80;

#charset koi8-r;

#access_log  logs/host.access.log  main;

location / {
    root   /home/webuser1/www/public;
    index  index.html index.htm index.php;

error_page  404              /404.html;
location = /404.html {
    root   /usr/share/nginx/html;

# redirect server error pages to the static page /50x.html
error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   /usr/share/nginx/html;

# pass the PHP scripts to FastCGI server listening on
location ~ \.php$ {
    root           html;
    fastcgi_index  index.php;
#   fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;


In Nginx logs, I have:

2013/05/18 15:21:52 [error] 2943#0: *1 FastCGI sent in stderr: "Primary script unknown"     while reading response header from upstream, client:, server:, request: "GET / HTTP/1.1", upstream: "fastcgi://", host: ""

How can I get this to work?

My answer:

You have placed your root directives in the wrong places.

root should be defined in the server block, not in each location block. This is one of the most common nginx misconfigurations.

To resolve the issue, remove all of the root directives from each location block, and place the correct root directive within the server block, not within any location.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.