Welcome! Log In Create A New Profile


Proper coding of location for php and proxy_pass

January 23, 2017 08:43PM
Hello All,

What is the correct coding of location section(s) for 2 Raspberry with nginx.

RPI1 is the main webpage and also is going to host owncloud (which uses https and php)
RPI2 is a weather station using plain http html and some php.

To catch requests to RPI2 I can use a text pattern in the URL. 'rpi'
Now my problem is that the RPI2 has some php and the RPI1 with owncloud has php.

I have tried 2 location segments but it seems the php always wins.

What is the correct way to code this?

Here's a tuned down version of the default config that shows the problem.
Just now I have commented out the php. This way 'owncloud is disabled but all URLs with 'rpi' (including those with php) are send to RPI2.

server {
listen 8000; ## listen for ipv4; this line is default and implied
#listen [::]:80 default_server ipv6only=on; ## listen for ipv6

root /media/usbstick/nginx/www;
index index.php index.html index.htm;

# Make site accessible from http://localhost/
server_name rpi3;

location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.html;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
ssi on;

# Pass /rpi Weather station to RPI1
location /rpi {

# pass the PHP scripts to FastCGI server listening on
#location ~ \.php$ {
#fastcgi_split_path_info ^(.+\.php)(/.+)$;
##fastcgi_pass unix:/var/run/php5-fpm.sock;
#fastcgi_index index.php;
#include fastcgi_params;

Here is a version of the full config which does not work for the weather station.

upstream php-handler {
#server unix:/var/run/php5-fpm.sock;

server {
listen 8000;
#server_name localhost;
server_name xxxxxxx.dyndns.ws;
return 301 https://$server_name$request_uri; # enforce https

server {
listen 443 ssl;
#server_name localhost;
server_name xxxxxxx.dyndns.ws;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";

ssl_certificate /etc/letsencrypt/live/xxxxxxx.dyndns.ws/cert.pem;
ssl_certificate_key /etc/letsencrypt/live/xxxxxxx.dyndns.ws/privkey.pem;

# Path to the root of your installation
root /media/usbstick/nginx/www/owncloud;

client_max_body_size 2000M; # set max upload size
fastcgi_buffers 64 4K;

rewrite ^/caldav(.*)$ /remote.php/caldav$1 redirect;
rewrite ^/carddav(.*)$ /remote.php/carddav$1 redirect;
rewrite ^/webdav(.*)$ /remote.php/webdav$1 redirect;

index index.php;
error_page 403 /core/templates/403.php;
error_page 404 /core/templates/404.php;

location = /robots.txt {
allow all;
log_not_found off;
access_log off;

location ~ ^/(?:\.htaccess|data|config|db_structure\.xml|README) {
deny all;
location / {
# The following 2 rules are only needed with webfinger
rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;

rewrite ^/.well-known/carddav /remote.php/carddav/ redirect;
rewrite ^/.well-known/caldav /remote.php/caldav/ redirect;

rewrite ^(/core/doc/[^\/]+/)$ $1/index.html;

try_files $uri $uri/ index.php;

location ~ \.php(?:$|/) {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param HTTPS on;
fastcgi_pass php-handler;

# Optional: set long EXPIRES header on static assets
location ~* \.(?:jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {
expires 30d;
# Optional: Don't log access to assets
access_log off;

# Pass /rpi Weather station to RPI1
location /rpi {


Thanks for helping,
Subject Author Posted

Proper coding of location for php and proxy_pass

forumacct January 23, 2017 08:43PM

Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 93
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready