a year ago
i have a project with nginx + php-fpm using docker, pulling from my github repo. When i push a new commit, the Railway makes the deploy automatically and build the containers all together. but sometimes after all the deploys, when ill access the page in the nginx, i have the 502 error (bad gateway). I think its because when the nginx are deploying, sometimes the php is not up yet. I tried to set true the "Wait for CI" in the nginx to wait php-fpmbut it doesnt changed anything, and i think the nginx depends on php-fpm to work, because of the fast-cgi config on the nginx .conf file. It would be good if we had some kind of order to deploy the containers
7 Replies
a year ago
Hey there! We've found the following might help you get unblocked faster:
- 🧵 Need to increase nginx upload limit beyond 1MB for PHP app - Custom configs failed
- 🧵 nginx with php-fpm
- 🧵 Laravel + MySQL: "Connection refused" despite successful netcat connection
If you find the answer from one of these, please let us know by solving the thread!
a year ago
You could try using a health check in your docker-compose file
version: '3.8'
services:
php:
build: ./php
expose:
- 9000
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost"]
interval: 10s
timeout: 5s
retries: 5
nginx:
build: ./nginx
ports:
- "80:80"
depends_on:
php:
condition: service_healthy
phoenixauro
You could try using a health check in your docker-compose file `version: '3.8'` `services:` ` php:` ` build: ./php` ` expose:` ` - 9000` ` healthcheck:` ` test: ["CMD", "curl", "-f", "http://localhost"]` ` interval: 10s` ` timeout: 5s` ` retries: 5` ` nginx:` ` build: ./nginx` ` ports:` ` - "80:80"` ` depends_on:` ` php:` ` condition: service_healthy`
a year ago
i don't use docker-compose, only Dockerfile, i already tried using dockercompose but seems Railway don't support docker-compose files. But yes, it works on my local machine using Docker application.
a year ago
Then use an entry point script for you nginx to control it's start
#!/bin/bash
PHP_HOST="php"
PHP_PORT=9000
MAX_RETRIES=30
SLEEP_TIME=1
echo "Waiting for PHP-FPM at $PHP_HOST:$PHP_PORT..."
for ((i=1;i<=MAX_RETRIES;i++)); do
if nc -z "$PHP_HOST" "$PHP_PORT"; then
echo "PHP-FPM is up!"
break
fi
echo " Attempt $i/$MAX_RETRIES: PHP-FPM not ready, retrying in $SLEEP_TIME sec..."
sleep $SLEEP_TIME
done
if (( i > MAX_RETRIES )); then
echo "PHP-FPM did not start within expected time. Exiting."
exit 1
fi
# Start Nginx
echo " Starting Nginx..."
nginx -g "daemon off;"
phoenixauro
Then use an entry point script for you nginx to control it's start #!/bin/bash PHP\_HOST="php" PHP\_PORT=9000 MAX\_RETRIES=30 SLEEP\_TIME=1 echo "Waiting for PHP-FPM at $PHP\_HOST:$PHP\_PORT..." for ((i=1;i<=MAX\_RETRIES;i++)); do if nc -z "$PHP\_HOST" "$PHP\_PORT"; then echo "PHP-FPM is up!" break fi echo " Attempt $i/$MAX\_RETRIES: PHP-FPM not ready, retrying in $SLEEP\_TIME sec..." sleep $SLEEP\_TIME done if (( i > MAX\_RETRIES )); then echo "PHP-FPM did not start within expected time. Exiting." exit 1 fi \# Start Nginx echo " Starting Nginx..." nginx -g "daemon off;"
a year ago
a year ago
You script doesn't have executable permissions.
Add this line after COPY
RUN chmod +x /docker-entrypoint.d/start.sh
a year ago