首页 文章

Nginx负载均衡与专用的php-fpm服务器

提问于
浏览
4

我用nginx php-fpm和mysql安装了服务器 . 我有另一台服务器只安装了php-fpm,所以想用作负载 balancer . 但是当我使用这个带有php-fpm的dedacted服务器作为负载均衡器时,我在打开页面时遇到错误:“拒绝访问” .

/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时 - 一切正常 .

2 回答

  • 1

    如果由security.limit_extensions directive引起的's a blank page with 2735111 on it, it'已添加到php-fpm .

    如果你没有在你的php-fpm配置中使用它,它默认为.php并防止所有其他文件类型被PHP解释器解析,在尝试这样做时产生“拒绝访问” .

  • 3

    您收到该错误,因为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

相关问题