2011-03-16 62 views
4

我用nginx + php-fpm和mysql獲得了服務器設置。 我有另一臺服務器只安裝php-fpm,所以想用作負載平衡。 但是當我用php-fpm作爲負載均衡器使用這個授權服務器時,打開頁面時出現錯誤:「拒絕訪問」。Nginx負載均衡與專用的php-fpm服務器

/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; 
    } 
} 

爲什麼我得到這個錯誤?當我只將fastcgi_pass更改爲127.0.0.1:9000時 - 一切正常。

回答

1

您收到該錯誤是因爲PHP-FPM服務器上不存在PHP-FPM文件。

fastcgi_param SCRIPT_FILENAME /home/www/$fastcgi_script_name;

或(我用這個,因爲它爲多個虛擬主機,很簡單)

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

它似乎Nginx的只是提供與文件的位置PHP-FPM服務器,PHP -FPM服務器然後呈現它。最簡單的解決方案是將文檔根rsync同步到PHP-FPM服務器。

這篇文章可以解釋的細節:http://code.google.com/p/sna/wiki/NginxWithPHPFPM

3

如果它與「拒絕訪問」就可以了,它是由已添加到PHP-FPM security.limit_extensions directive造成一個空白頁。

如果您在php-fpm配置中沒有它,它將默認爲.php,並且在嘗試這樣做時會阻止PHP解釋器生成「訪問被拒絕」的所有其他文件類型。