Nginx配置 - 上游 - 备份服务器

时间:2016-11-02 20:34:04

标签: php nginx backend

我和我的上游有关,我想知道我的nginx配置有什么问题:

upstream backends {
server 127.0.0.1:80;
server 188.200.200.200 backup;
}

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/html;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html index.php;

    server_name localhost;

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ =404;
        proxy_read_timeout 150;
        proxy_pass http://backends;
        proxy_set_header Host $host;
        proxy_next_upstream error timeout http_500 http_502 http_503 http_504;
 }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000


location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_read_timeout 150;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
            fastcgi_buffer_size 128k;
            fastcgi_buffers 4 256k;
            fastcgi_busy_buffers_size 256k;

    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
            deny all;
    }

 location ~* \.      (jpg|jpeg|gif|png|css|js|ico|xml|woff|ttf|otf|svg|woff2|eot)$ {
     access_log        off;
     log_not_found     off;
     expires           30d;
 }

它在日志中提供此消息: 连接到上游时连接失败(111:连接被拒绝),客户端:xx.xx.xx.xx,服务器:localhost,请求:" GET / HTTP / 1.1",上游:&#34 ; fastcgi的://127.0.0.1:9000"

有人可以帮助我吗?

提前致谢

1 个答案:

答案 0 :(得分:0)

您似乎正在请求.php文件,该文件由第二个位置块提供。在此块中,nginx尝试根据127.0.0.1:9000 - 指令连接到fastcgi_pass 127.0.0.1:9000;。但似乎没有FastCGI-daemon在这个地址运行。

如果您请求/并且没有来自index - 指令的索引文件,则可能会发生同样的情况。最后一个条目(index.php)也会激活第二个位置。