502 Error when I visit the app in the browser
franko172000
PROOP

a month ago

I recently created a new service running on a docker image.

However, after successful deployment, I keep getting a 502 gateway error on Railway.

The same image works on other platforms like my local computer and on AWS EC2 instance.

The major issue here now is that I am unable to view errors generated from the application so I can debug and fix the issue.

Solved$20 Bounty

Pinned Solution

Your Nginx config uses listen ${PORT}; , this won't work as Nginx does not support using env variables in its config. If the networking config in the image you showed, routes traffic to your Nginx container You should change it to listen 9000; instead. Addtionally, if Nginx is configured to listen on port 9000 your PHP-FPM should listen on a different port (like 9001).

8 Replies

Railway
BOT

a month ago

This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.

Status changed to Open Railway about 1 month ago


a month ago

What are you trying to deploy? Have you checked the troubleshoot common issues guide?

See: https://docs.railway.com/networking/troubleshooting/application-failed-to-respond


medim

What are you trying to deploy? Have you checked the troubleshoot common issues guide? See: <https://docs.railway.com/networking/troubleshooting/application-failed-to-respond>

franko172000
PROOP

a month ago

Yes. I have checked the doc. I am trying to deploy a Laravel application with a Reactjs Frontend bundled together. PHP-FPM is listening on port 9000 as defined in the Nginx config.

But I still get the 502 gateway error


a month ago

Do you have a PORT env var set to 9000 on your Railway service?


medim

Do you have a `PORT` env var set to `9000` on your Railway service?

franko172000
PROOP

a month ago

No. Because the app does not use the port via an env var. Here is the screenshot which shows that traffic is routed to port 9000

Attachments


a month ago

Make sure your app also binds to 0.0.0.0 and not localhost and or 127.0.0.1


medim

Make sure your app also binds to `0.0.0.0` and not `localhost` and or `127.0.0.1`

franko172000
PROOP

a month ago

Here is the Nginx config below.

server { listen ${PORT}; index index.php index.html; error_log /var/log/nginx/error.log; access_log /var/log/nginx/access.log; root /var/www/html/public; location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; } location / { try_files $uri $uri/ /index.php?$query_string; gzip_static on; } }

Are you saying I should change this, fastcgi_pass 127.0.0.1:9000; to fastcgi_pass 0.0.0.0:9000;


franko172000

Here is the Nginx config below. server { listen ${PORT}; index index.php index.html; error\_log /var/log/nginx/error.log; access\_log /var/log/nginx/access.log; root /var/www/html/public; location \~ \\.php$ { try\_files $uri =404; fastcgi\_split\_path\_info ^(.+\\.php)(/.+)$; fastcgi\_pass 127.0.0.1:9000; fastcgi\_index index.php; include fastcgi\_params; fastcgi\_param SCRIPT\_FILENAME $document\_root$fastcgi\_script\_name; fastcgi\_param PATH\_INFO $fastcgi\_path\_info; } location / { try\_files $uri $uri/ /index.php?$query\_string; gzip\_static on; } } Are you saying I should change this, fastcgi\_pass 127.0.0.1:9000; to fastcgi\_pass 0.0.0.0:9000;

Your Nginx config uses listen ${PORT}; , this won't work as Nginx does not support using env variables in its config. If the networking config in the image you showed, routes traffic to your Nginx container You should change it to listen 9000; instead. Addtionally, if Nginx is configured to listen on port 9000 your PHP-FPM should listen on a different port (like 9001).


darseen

Your Nginx config uses `listen ${PORT};` , this won't work as Nginx does not support using env variables in its config. If the networking config in the image you showed, routes traffic to your Nginx container You should change it to `listen 9000;` instead. Addtionally, if Nginx is configured to listen on port 9000 your PHP-FPM should listen on a different port (like 9001).

franko172000
PROOP

a month ago

Thank you.

I have been able to fix it.

I removed the $PORT variable from Nginx, add a custom port in the network settings of the service and then made Nginx listen on the custom port.


Status changed to Solved medim about 1 month ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...