nginx try_files rewrite if exists proxy if doesn't -


i using nginx docker container (https://github.com/jwilder/nginx-proxy) proxy requests instances of apache running in other docker containers. each subdomain gets own apache docker container. 1 of these subdomains (sub1) requires special rules:

if url begins "foo" nginx check if file exists. if file exists, should rewrite url access control script (imagecontrol.php), , pass usual apache container. if file not exist want request proxied remote server.

i thought set things correctly, reason nginx sending request remote server - if file exists locally.

here relevant portion of nginx config file within docker container:

default.conf (included nginx.conf):

upstream sub1.mydomain.com {             ## can connect "dockerized_default" network             # dockerized_sub1             server 172.18.0.2:80; } server {     server_name sub1.mydomain.com;     listen 80 ;     access_log /var/log/nginx/access.log vhost;     include /etc/nginx/vhost.d/sub1.mydomain.com;     location / {         proxy_pass http://sub1.mydomain.com;     } }   

/etc/nginx/vhost.d/sub1.mydomain.com :

location ^~ /foo/ {     root /path/to/dockerized/webroot;     try_files $uri @rewrite @remoteproxy; }  location @remoteproxy {    include vhost.d/remoteproxy.inc;    proxy_pass http://remote.ip.address.here; }  location @rewrite {     rewrite ^/(.*)$ /imagecontrol.php?file=$1 break; } 

please note not want nginx try run imagecontrol.php (i not using php-fpm) - want nginx pass upstream apache container.

desired behavior example:

  1. (this part works)

  2. (this part not work)

i'd appreciate help.

you may have more luck using if -e expression:

location ^~ /foo/ {     root /path/to/dockerized/webroot;     if (-e $request_filename) {         rewrite ^/(.*)$ /imagecontrol.php?file=$1 last;     }     include vhost.d/remoteproxy.inc;     proxy_pass http://remote.ip.address.here; } 

see this document more.


Comments

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -