Nginx, proxy_pass and fastcgi/php


Nginx, proxy_pass and fastcgi/php

我正在树莓上运行一个小型nginx实例。到目前为止,这一切都很顺利。它使用SSL和PHP,并按预期运行。现在我计划使用proxy_pass将请求转发到/photo到我的本地磁盘站。

复盆子IP是192.168.178.3,磁盘站是192.168.178.2。直接访问磁盘站是可以的。

nginx-config:

server {
  ...
  location / {
    root /var/www;
  }
  location /photo {
    #rewrite ^ $scheme://$host/;
    proxy_pass http://192.168.178.2$uri;
  } 
  location ~ ^(?<script_name>.+?'.php)(?<path_info>/.*)?$ {
    try_files $script_name =404;
    include fastcgi_params;
    fastcgi_param PATH_INFO $path_info;
    fastcgi_param HTTPS on;
    fastcgi_read_timeout 3600s;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
  }
}

不幸的是,nginx处理所有*.php请求,但php文件的请求应该使用proxy_pass设置转发到diskstation。

例如,http://192.168.178.3/photo/scripts/uistrings.php?v=6.2-2858&ln=ger返回一个404,但当直接发送到磁盘站时,它可以正常工作。对于所有其他文件,如PNG或CSS,proxy_pass运行良好。

如何修复php文件问题?

location ^~ /photo {
    ....
}

这应该行得通。阅读http://nginx.org/r/location详细信息。