I have a UWSGI Django API running which is configured like this in NGINX:
upstream django_api {
server 127.0.0.1:8088;
}
server {
server_name api.domain.com;
root /home/www/api/domain/;
access_log /var/log/nginx/api.domain.com-access.log;
error_log /var/log/nginx/api.domain.com-error.log;
location / {
uwsgi_pass django_api;
include uwsgi_params;
uwsgi_read_timeout 600;
add_header Host $hostname;
}
}
And a node app configured like this:
server {
server_name app.domain.com;
root /home/www/app/dist/;
access_log /var/log/nginx/app.domain.com-access.log;
error_log /var/log/nginx/app.domain.com-error.log;
location / {
try_files $uri $uri/ /index.html;
proxy_cache domain_zone;
add_header X-Proxy-Cache $upstream_cache_status;
}
}
I want to serve the Django api from a sub path of my app (like app.domain.com/api/) as well as api.domain.com.
Normally I would think that I need a new location block under app.domain.com like this:
location /api/ {
rewrite ^/api/(.*)$ /$1 break;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header HOST $http_host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://localhost:8088;
}
But it doesn't work and I get a 500 error. I have tried many other configs with no luck. Can this be done?
Best Answer
Passing the
uwsgi_pass
did the trick apparently, thank you Alexy for the advice.The new config is like this now: