Deployment Issue: Nginx Container Not Responding (503 Error)

After successfully deploying my Laravel application with Dockerfile to Railway, I am encountering a 503 error when trying to access the application using the provided URL below. Deployment Details: Project Id: 5eff00b6-887c-4fb9-9f2f-02c7fb94d78c Deployment URL: https://innoscripta-assessment-backend-production.up.railway.app/ Steps Taken So Far: 1 - Checked Nginx Configuration: I reviewed the Nginx configuration file and ensured that it is properly set up to route traffic to the Laravel PHP-FPM container. 2 - Verified Environment Variables: I have confirmed that all the required environment variables, such as DB_CONNECTION, DB_HOST, DB_PORT, DB_DATABASE, DB_USERNAME, DB_PASSWORD, and others, are correctly set in the railway environment. 3 - Restarted the Containers: I tried restarting all the containers, but the issue persists. 4 - Verified Port Mapping: I have confirmed that the Nginx container is correctly mapped to port 80 on the host machine, and the Laravel PHP-FPM container is mapped to port 9000. 5 - Reviewed Application Logs: The logs for the app-1 container do not show any errors. It only displays the following message: "[03-Aug-2023 23:47:00] NOTICE: fpm is running, pid 1 [03-Aug-2023 23:47:00] NOTICE: ready to handle connections." and I do not see any error logs related to Nginx in the railway dashboard logs (I only see the app container logs). Request for Assistance: I kindly request your support in identifying and resolving the root cause of the issue. Please investigate the Nginx container's logs and any other relevant logs that may help pinpoint the problem. Any insights or guidance to resolve this matter would be greatly appreciated. Please let me know if you require any further information to assist in resolving this issue.
61 Replies
Percy
Percy16mo ago
Project ID: 5eff00b6-887c-4fb9-9f2f-02c7fb94d78c
Brody
Brody16mo ago
have nginx listen on a non privileged port like 8080, and then in your railway service variables set a PORT variable to 8080 as well
coldgroove
coldgrooveOP16mo ago
Changed the nginx.conf file and added a PORT variable set to 8080 as well and redeployed. No luck 😦 here is my file:
server {
listen 8080;
server_name localhost;
root /var/www/html/public;

index index.php index.html index.htm;

location / {
try_files $uri $uri/ /index.php?$query_string;
}

location ~ \.php$ {
fastcgi_pass app:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

location ~ /\.ht {
deny all;
}
}
server {
listen 8080;
server_name localhost;
root /var/www/html/public;

index index.php index.html index.htm;

location / {
try_files $uri $uri/ /index.php?$query_string;
}

location ~ \.php$ {
fastcgi_pass app:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

location ~ /\.ht {
deny all;
}
}
Brody
Brody16mo ago
show me your service variables please also, have you tried deploying your app with nixpacks instead of a dockerfile?
coldgroove
coldgrooveOP16mo ago
No, I don't know much about deploying with nixpacks. Do you need the values of the env vars or you want to check the keys only?
Brody
Brody16mo ago
I just wanted a screenshot, now you've shown me all your keys, please go and regen them
coldgroove
coldgrooveOP16mo ago
np i changed the values keeping the general structure
Brody
Brody16mo ago
send your dockerfile please
coldgroove
coldgrooveOP16mo ago
# Use the official PHP FPM 8.1 image as the base image
FROM php:8.1-fpm

# Install system dependencies and PHP extensions
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
curl \
libpq-dev \
libjpeg-dev \
libpng-dev \
libfreetype6-dev \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd pdo pdo_mysql

# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Set the working directory inside the container
WORKDIR /var/www/html

# Expose port 9000 for PHP-FPM
EXPOSE 9000

# Start PHP-FPM
CMD ["php-fpm"]
# Use the official PHP FPM 8.1 image as the base image
FROM php:8.1-fpm

# Install system dependencies and PHP extensions
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
curl \
libpq-dev \
libjpeg-dev \
libpng-dev \
libfreetype6-dev \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd pdo pdo_mysql

# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Set the working directory inside the container
WORKDIR /var/www/html

# Expose port 9000 for PHP-FPM
EXPOSE 9000

# Start PHP-FPM
CMD ["php-fpm"]
Brody
Brody16mo ago
does php:8.1-fpm include nginx?
coldgroove
coldgrooveOP16mo ago
i don't think so
root
root16mo ago
Try adding nginx to the apt-get install command then?
Brody
Brody16mo ago
I think you should try deploying with nixpacks
root
root16mo ago
^ this I have spent rather an amount of time getting the Nixpacks PHP provider to Just Work™️, so hopefully it should.
Brody
Brody16mo ago
spoiler alert, it's still sub par what this involves is removing your dockerfile and nginx.conf
root
root16mo ago
You can also just rename them to .bak or something if you want, to keep them around
Brody
Brody16mo ago
^ this
coldgroove
coldgrooveOP16mo ago
Oh man, i really don't know anything about nixpacks and I don't have time for it (this project was for an assessment and I'm at the end of the deadline)
root
root16mo ago
You can just delete those two files and it should Just Work™️ That's the point of nixpacks
Brody
Brody16mo ago
took the words right out of my fingers
coldgroove
coldgrooveOP16mo ago
Oh yeah so no configuration files like Dockerfile whatsoever?
Brody
Brody16mo ago
that's the point
root
root16mo ago
zigacktly
coldgroove
coldgrooveOP16mo ago
aight lemme try it
Brody
Brody16mo ago
nixpacks probably won't pick up on the libpg libjpeg etc stuff though
root
root16mo ago
it might I'm not sure
Brody
Brody16mo ago
depends on how well you did with the php provider
root
root16mo ago
It'll install the required extensions, which should hopefully have such things as dependencies
Brody
Brody16mo ago
hopefully ™️
root
root16mo ago
™️©️ ®️
Brody
Brody16mo ago
😬
coldgroove
coldgrooveOP16mo ago
returned 403 😄
root
root16mo ago
nooooooo
Brody
Brody16mo ago
hey that's better than 503!!
root
root16mo ago
oh wait what does the page say Understand here, none of us are PHP developers
coldgroove
coldgrooveOP16mo ago
me neither brotha first time trying it I have this in the deploy logs tho: "Looks like your app is listening on 127.0.0.1. You may need to listen on 0.0.0.0 instead."
root
root16mo ago
I wrote the provider, but I'd still rate myself as a beginner hrrrm could you send the logs?
root
root16mo ago
well that's weird
coldgroove
coldgrooveOP16mo ago
root
root16mo ago
I don't know where that message popup is coming from, you can ignore it oh I see where it's coming from. you can still ignore it though hmm do you have a public directory?
coldgroove
coldgrooveOP16mo ago
oh shii, do i need to remove the .dockerignore too?
root
root16mo ago
no, it's using nixpacks do you have a public directory in your app though?
coldgroove
coldgrooveOP16mo ago
I ve a public directory in the root
root
root16mo ago
all this is nixpacks doing black magic with Perl regexes to tell you that your app might have problems
root
root16mo ago
oh, I think I might know what's happening What are the permissions on the public directory? wait nvm I'm tired, disregard that question
coldgroove
coldgrooveOP16mo ago
I have .htaccess file inside the public directory if you mean that
root
root16mo ago
.htaccess won't actually do anything here, since this is Nginx Try adding a nixpacks.toml to your project:
[start]
cmd = "chmod ugo+rwx /app/public && perl /assets/prestart.pl /assets/nginx.template.conf /nginx.conf && (php-fpm -y {} & nginx -c /nginx.conf)"
[start]
cmd = "chmod ugo+rwx /app/public && perl /assets/prestart.pl /assets/nginx.template.conf /nginx.conf && (php-fpm -y {} & nginx -c /nginx.conf)"
Brody
Brody16mo ago
see this is what I mean by subpar, you shouldn't need to be chmod'ing anything
root
root16mo ago
s/subpar/secure Nginx runs as a different user so people can't hack your server
Brody
Brody16mo ago
doesn't the chmod in your nixpacks.toml undo anything that was secure
root
root16mo ago
shhh
coldgroove
coldgrooveOP16mo ago
nope, didnt work
coldgroove
coldgrooveOP16mo ago
couldnt even open it?
root
root16mo ago
oh oops
[start]
cmd = "chmod ugo+rwx /app/public && perl /assets/prestart.pl /assets/nginx.template.conf /nginx.conf && (php-fpm -y /assets/php-fpm.conf & nginx -c /nginx.conf)"
[start]
cmd = "chmod ugo+rwx /app/public && perl /assets/prestart.pl /assets/nginx.template.conf /nginx.conf && (php-fpm -y /assets/php-fpm.conf & nginx -c /nginx.conf)"
coldgroove
coldgrooveOP16mo ago
I'd renamed the dockerfiles to .bak but i think it was still picking up those for some reason removing those entirely worked tho
root
root16mo ago
huh that is very odd anyway, glad it works!
coldgroove
coldgrooveOP16mo ago
classic home page returns i'll test the api routes now but thank you guys for the assistance!
root
root16mo ago
It was definitely using nixpacks though, so I'm confused no problem!
Brody
Brody16mo ago
🥳
Want results from more Discord servers?
Add your server