1个nginx服务器多个php服务器

时间:2016-08-28 10:12:54

标签: nginx cluster-computing

我错过了什么? 让我们说这个简单的conf:

upstream php {
  server 111.1111.1111.1111:9000;
}
server {
    listen 80 reuseport;


    root /var/www/html/public/;
    index index.php;
    location / {
        set $orig_uri $uri;
        try_files $uri $uri/ /index.php?$query_string;
    }

location ~ \.php$ {
        ssi on;
        include snippets/fastcgi-php.conf;
        fastcgi_param REQUEST_URI $orig_uri$is_args$args;
        fastcgi_cache_key "$scheme$request_method$orig_uri$is_args$args";
        add_header X-Cache-Key $scheme$request_method$orig_uri$is_args$args;
        add_header X-Cache $upstream_cache_status;
        # With php5-cgi alone:
        #fastcgi_pass 127.0.0.1:9000;
        # With php5-fpm:
        #fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_pass php;
        }
}

nginx如何访问" / var / www / html / public /"在不同的服务器?如何知道文件是否存在?我试着玩它,我总是得到

  

404 Not Found

所以我错过了一些东西但是无法理解,如果php服务器没有安装nginx

1 个答案:

答案 0 :(得分:0)

  

nginx如何访问" / var / www / html / public /"在不同的   服务器?如何知道该文件是否存在?

nginx无法确定上游PHP服务中是否存在该文件。它会将脚本路径名传递给PHP服务,如果它不存在,PHP服务将返回404响应。

PHP服务可能使用fastcgi_param SCRIPT_FILENAME参数来查找上游脚本文件。该参数应在snippets/fastcgi-php.conf文件中定义。

通常将其设置为$document_root$fastcgi_script_name的值。 $document_root的值由配置文件中的root指令设置。

仅当上游服务器上的脚本放在与nginx服务器指定的完全相同的目录层次结构中时,此操作才有效。否则,您可能需要手工处理SCRIPT_FILENAME参数的值。