R
Railwayβ€’15mo ago
theodor

nginx revere proxy 503 error

Hi! I wanted to set up a reverse NGINX proxy with mixpanel. I used the dockerfile provided by them:
FROM nginx
COPY nginx.conf /etc/nginx/nginx.conf
FROM nginx
COPY nginx.conf /etc/nginx/nginx.conf
And this configuration:
events {}
http {
server {
listen 80 default backlog=16384;
listen [::]:80 default backlog=16384;

location /lib.min.js {
proxy_set_header X-Real-IP $http_x_forwarded_for;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_pass https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js;
}

location /lib.js {
proxy_set_header X-Real-IP $http_x_forwarded_for;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_pass https://cdn.mxpnl.com/libs/mixpanel-2-latest.js;
}

location /decide {
proxy_set_header Host decide.mixpanel.com;
proxy_set_header X-Real-IP $http_x_forwarded_for;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_pass https://decide.mixpanel.com/decide;
}

location / {
proxy_set_header Host api.mixpanel.com;
proxy_set_header X-Real-IP $http_x_forwarded_for;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_pass https://api.mixpanel.com/;
}
}
}
events {}
http {
server {
listen 80 default backlog=16384;
listen [::]:80 default backlog=16384;

location /lib.min.js {
proxy_set_header X-Real-IP $http_x_forwarded_for;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_pass https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js;
}

location /lib.js {
proxy_set_header X-Real-IP $http_x_forwarded_for;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_pass https://cdn.mxpnl.com/libs/mixpanel-2-latest.js;
}

location /decide {
proxy_set_header Host decide.mixpanel.com;
proxy_set_header X-Real-IP $http_x_forwarded_for;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_pass https://decide.mixpanel.com/decide;
}

location / {
proxy_set_header Host api.mixpanel.com;
proxy_set_header X-Real-IP $http_x_forwarded_for;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_pass https://api.mixpanel.com/;
}
}
}
I also enabled a custom domain which is verified (reverse-proxy.rizzgpt.app). However, I'm getting a 503 when I try to load it. Any idea why?
9 Replies
Percy
Percyβ€’15mo ago
Project ID: 120b5ec5-59d8-4087-84ae-4e0b3d934aa7
theodor
theodorOPβ€’15mo ago
120b5ec5-59d8-4087-84ae-4e0b3d934aa7
Brody
Brodyβ€’15mo ago
do
listen 8080 default backlog=16384;
listen [::]:8080 default backlog=16384;
listen 8080 default backlog=16384;
listen [::]:8080 default backlog=16384;
instead then set a service variable PORT=8080
theodor
theodorOPβ€’15mo ago
gotcha thanks! it works! thanks!
Brody
Brodyβ€’15mo ago
no problem πŸ™‚
theodor
theodorOPβ€’15mo ago
why was that necessary? just curious
Brody
Brodyβ€’15mo ago
railway had no way of knowing nginx was listening on port 80 so i asked you to have nginx listen on 8080 purely for good practice since 8080 is an unprivlaged port, then you set PORT=8080 to tell railway what port your app listens on
theodor
theodorOPβ€’15mo ago
ah i see! so PORT=8080 is the magic formula here
Brody
Brodyβ€’15mo ago
railway randomly generates a PORT variable for you, normally you want to listen on that, but thats not exactly possible with nginx, so we have to resort to setting a fixed port
Want results from more Discord servers?
Add your server