4
votes

I got server setup with nginx+php-fpm and mysql. I have another server with only installed php-fpm, so wanted to use as load balance. But when I am using this dedacted server with php-fpm as load balancer, I got error when opening page: "Access denied."

/etc/nginx/nginx.conf

user www-data;
worker_processes  3;

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    server_names_hash_bucket_size 64;
    access_log  /var/log/nginx/access.log;

    sendfile        on;
    #tcp_nopush      on;

    keepalive_timeout   65;
    tcp_nodelay         on;

    #gzip                on;

    upstream php {
        server dedicatedserverip:9000;
    }

    include /etc/nginx/sites-enabled/*;
}

/etc/nginx/sites-enabled/site.org.conf

server {
    listen   81;
    server_name site.org www.site.org;
    access_log  /var/log/nginx/site.org.log;
    error_log   /var/log/nginx/site.org.log;
    root        /home/www/site.org;
    index       index.php; 

    location ~ .php$ {
        fastcgi_pass  php;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /home/www/$fastcgi_script_name;
    }
} 

Why I got this error? When I change only the fastcgi_pass to 127.0.0.1:9000 - all work fine.

2

2 Answers

3
votes

If it's a blank page with "Access denied" on it, it's caused by security.limit_extensions directive that has been added to php-fpm.

If you don't have it in your php-fpm configuration, it defaults to .php and prevents all other file types from being parsed by the PHP interpreter producing "Access denied" when trying to do so.

1
votes

You received that error because the files PHP-FPM don't exist on the PHP-FPM server.

fastcgi_param SCRIPT_FILENAME /home/www/$fastcgi_script_name;

or (I use this because it's simpler for multiple vhosts)

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

It seems Nginx simply provides the PHP-FPM server with the location of the file, and the PHP-FPM server then renders it. The simplest solution is to rsync the document root to the PHP-FPM server.

This post can explain details: http://code.google.com/p/sna/wiki/NginxWithPHPFPM