3 months ago
I Have Error Status Code 502 i try to fixed it but not solving work
10 Replies
3 months ago
i need help to fix that error i set port as 8080 as the must be but not thing solve it
Status changed to Open itsrems • 3 months ago
3 months ago
yes i set
listen 8080;
in railway-nginx.confStatus changed to Open itsrems • 3 months ago
3 months ago
if you manually set listen 8080; inside your config file you have to make sure railway knows to look for traffic there
go to your service Variables tab in the dashboard and add this environment variable
PORT with the value 8080
if you dont set that railway might be assigning a random port number to the environment that your nginx isnt listening on which causes the 502
if that doesnt fix it check your Deploy Logs and paste the error output here using a code block
paste logs here
sometimes nginx crashes on startup if the config syntax is wrong so the logs will tell us exactly whats up
hope that helps
3 months ago
OP can also map the URL to the designated port via service settings.
3 months ago
I Added PORT Variable in Variable of App Service Value is 8080
but not work but not work yet
this is my railway-nginx.conf
server {
listen 8080;
server_name _;
root /var/www/html/public;
index index.php index.html;
# Add server tokens off for security
server_tokens off;
# gzip
gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_buffering off;
fastcgi_read_timeout 300;
}
location ~ /\.(?!well-known).* {
deny all;
}
# Store Static Files
location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff|woff2|ttf|eot)$ {
expires 30d;
add_header Cache-Control "public, immutable";
}
}
not also still give me error 502 when i try to domain on browser3 months ago
that's my build log
[Region: europe-west4]
=========================
Using Detected Dockerfile
=========================
context: qvxn-CsRq
internal
load build definition from Dockerfile
0ms
internal
load metadata for docker.io/library/composer:latest
695ms
internal
load metadata for docker.io/library/php:8.2-fpm-alpine
696ms
auth
library/php:pull token for registry-1.docker.io
0ms
auth
library/composer:pull token for registry-1.docker.io
0ms
stage-0
8ms
internal
load build context
0ms
9ms
stage-0
COPY . . cached
0ms
stage-0
COPY start.sh /start.sh cached
0ms
stage-0
COPY php-fpm.conf /usr/local/etc/php-fpm.d/zz-docker.conf cached
0ms
stage-0
COPY railway-nginx.conf /etc/nginx/http.d/default.conf.template cached
0ms
stage-0
RUN composer install --no-dev --optimize-autoloader --no-scripts --no-interaction cached
0ms
stage-0
RUN php artisan config:clear && php artisan route:clear && php artisan view:clear cached
0ms
stage-0
WORKDIR /var/www/html cached
0ms
stage-0
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer cached
0ms
stage-0
RUN apk update && apk add --no-cache nginx git curl libxml2-dev postgresql-dev zip unzip supervisor net-tools netcat-openbsd && docker-php-ext-install pdo pdo_pgsql bcmath opcache cached
0ms
stage-0
RUN chmod +x /start.sh cached
0ms
stage-0
RUN chown -R www-data:www-data /var/www/html/storage /var/www/html/bootstrap/cache && chmod -R 775 /var/www/html/storage /var/www/html/bootstrap/cache cached
0ms
stage-0
COPY composer.json composer.lock ./ cached
0ms
auth
sharing credentials for production-europe-west4-drams3a.railway-registry.com
0ms
importing to docker
7s
Build time: 9.91 seconds
3 months ago
i don't know why i still get that error status code 502
Status changed to Open brody • 3 months ago
3 months ago
here also deploy log Starting Container
Dropping all tables ........................................... 24.34ms DONE
INFO Running migrations.
0001_01_01_000000_create_users_table .......................... 42.93ms DONE
0001_01_01_000001_create_cache_table .......................... 28.50ms DONE
0001_01_01_000002_create_jobs_table ........................... 30.58ms DONE
INFO Preparing database.
Creating migration table ...................................... 17.14ms DONE
3 months ago
hey @bmask2020 thanks for pasting those logs.
i think i see the issue. looking at the deploy logs in reply #9, it shows the database migrations running successfully... but then it just stops.
Creating migration table ...................................... 17.14ms DONE
i don't see any logs saying that Nginx or PHP-FPM actually started up. if your container finishes the migrations and doesn't explicitly start the web server processes, Railway won't have anything to connect to, which gives you that 502 Bad Gateway.
since you installed supervisor in your build process (saw it in reply #7), your startup script needs to trigger that to keep the app running.
can you paste the content of your start.sh file here?
we need to make sure it looks something like this at the end:
# ... migration commands ...
# start supervisor (or php and nginx)
/usr/bin/supervisord -c /etc/supervisord.conf
without seeing that file it's hard to know if the server is actually booting up.
also shoutout to @0x5b62656e5d for the port tip earlier, that part looks correct now in the nginx config. we just need to get the processes running.