Carsten Schütte
Carsten Schütte

Reputation: 4568

Nginx, proxy_pass and fastcgi/php

I am running a small nginx instance on my raspberry. This is working fine so far. It is using SSL and PHP and is running as expected. Now I plan to forward requests to /photo to my local diskstation using proxy_pass.

The Raspberry IP is 192.168.178.3, the diskstation is 192.168.178.2. Accessing the diskstation directly is fine.

The 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;
  }
}

Unfortunately, nginx handles all *.php requests, but the requests for php files should be forwarded to the diskstation using the proxy_pass setting.

For example, http://192.168.178.3/photo/scripts/uistrings.php?v=6.2-2858&ln=ger returns a 404 but works as expected when sent directly to the diskstation. For all other files like PNG or CSS the proxy_pass works fine.

How to fix the php file problem?

Upvotes: 1

Views: 6066

Answers (1)

Alexey Ten
Alexey Ten

Reputation: 14374

location ^~ /photo {
    ....
}

This should work. Read http://nginx.org/r/location for details.

Upvotes: 2

Related Questions