【问题标题】:Nginx, proxy_pass and fastcgi/phpNginx、proxy_pass 和 fastcgi/php
【发布时间】:2015-04-08 10:35:58
【问题描述】:

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

树莓IP是192.168.178.3,diskstation是192.168.178.2。直接访问 diskstation 就可以了。

nginx 配置:

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,但在直接发送到 diskstation 时可以正常工作。对于 PNG 或 CSS 等所有其他文件,proxy_pass 工作正常。

如何解决php文件问题?

【问题讨论】:

    标签: php nginx fastcgi proxypass


    【解决方案1】:
    location ^~ /photo {
        ....
    }
    

    这应该有效。阅读http://nginx.org/r/location了解详情。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-02
      • 1970-01-01
      • 2023-03-08
      • 2020-11-07
      • 1970-01-01
      • 1970-01-01
      • 2013-12-24
      相关资源
      最近更新 更多