i have 3 heroku apps
- frontend react
- backend node
- reverse-proxy nginx
- calls to reverse-proxy/api/?(.*) are frowarded to backend
- rest all calls to reverse-proxy are forwarded to frontend
the /etc/nginx/conf.d/default.conf code
upstream frontend {
server $FRONTEND_URL;
}
upstream backend {
server $BACKEND_URL;
}
server {
listen $PORT;
location / {
proxy_pass http://frontend;
proxy_set_header Host $FRONTEND_URL;
}
location /api {
rewrite /api/(.*) /$1 break;
proxy_pass http://backend;
proxy_set_header Host $BACKEND_URL;
}
}
issue
i am using cookie for authentication but the cookie being set by backend is not being 'forwarded'
now it works, changes i made:
- changing to
secure: falsein my node app did it for me (will add tls certificate later maybe) - suggested fix by @mariolu
now it looks like
location /api {
rewrite /api/(.*) /$1 break;
proxy_pass http://backend;
proxy_set_header Host $BACKEND_URL;
proxy_set_header Cookie $http_cookie;
}
app.set("trust proxy", true);