I have 2 web applications that I want available under http://example.com/demo1
and http://example.com/demo2
. My config below correctly reverse proxies to each site, and the site is mostly functional, but some API requests from my web application are 404'ing because they are omiting the /demo1
and /demo2
subdirectories from the Request URL. I suspect that I may need to update a header by appending the subdirectory, but I'm not sure. More details are below.
Here is my config:
worker_processes 1;
error_log stderr notice;
daemon off;
env DEMO1_PORT_8005_TCP_ADDR;
env DEMO2_PORT_8006_TCP_ADDR;
events {
worker_connections 1024;
}
http {
include /usr/local/openresty/nginx/conf/mime.types;
charset utf-8;
##
# Logging Settings
##
error_log /var/log/nginx/error.log warn;
access_log /var/log/nginx/access.log;
##
# Virtual Host Configs
#
server {
listen 80;
server_name example.com;
# root /var/www;
root /duwamish;
location /demo1 {
# load static files paths first (/static/(.)*), then reverse-proxy to demo
try_files $uri $uri/ @demo1;
}
location @demo1 {
set_by_lua $server_location 'return os.getenv("DEMO1_PORT_8005_TCP_ADDR")';
proxy_pass http://$server_location:8005;
proxy_set_header Host $host;
}
location /demo2 {
# load static files paths first (/static/(.)*), then reverse-proxy to demo
try_files $uri $uri/ @demo2;
}
location @demo2 {
set_by_lua $server_location 'return os.getenv("DEMO1_PORT_8005_TCP_ADDR")';
proxy_pass http://$server_location:8005;
proxy_set_header Host $host;
}
}
}
My site is loading fine, but I am getting 404's on some requests made by my demo1
and demo2
web applications because the Request URL is not being served. For example, the Request URL is http://example.com/api/submitted_thing?parameter=true
when I think it should be http://example.com/demo1/api/submitted_thing?parameter=true
Basically, I would like to use something like proxy_set_header Host $host/demo1
, but I don't think I can append a path to the Host header. Any suggestions?