File tree Expand file tree Collapse file tree 2 files changed +56
-4
lines changed Expand file tree Collapse file tree 2 files changed +56
-4
lines changed Original file line number Diff line number Diff line change 11# docker-nginx-php-fpm
2+
3+ ## Usage
4+
5+ Let's say you have ` /home/user/app/web ` folder which web root of your project.
6+ If the file physically exists on filesystem it is served by nginx.
7+ If file not present Nginx proxy a request to PHP-FPM.
8+ There must be a ` app.php ` inside the folder.
9+
10+ ```
11+ docker run --rm -it --env CUSTOM_DIR=/app/web -p 80:80 -v /home/user/app/:/app makasim/nginx-php-fpm
12+ ```
Original file line number Diff line number Diff line change 11#! /usr/bin/env bash
22
3- nginx -c /etc/nginx/nginx.conf -g ' daemon off;' 2>&1 &
4- php-fpm7.0 -R -F -c /etc/php/7.0/fpm/php-fpm.conf 2>&1 &
3+ TRAPPED_SIGNAL=false
54
6- trap " kill -15 %1; kill -15 %2; wait %1 %2;" SIGTERM SIGINT
5+ if [ -d $CUSTOM_DIR ]; then
6+ echo ' Custom dir setup'
7+ rm -rf /var/www/html;
8+ cd /var/www && ln -s $CUSTOM_DIR html
9+ fi
710
8- wait %2
11+ echo ' Starting NGINX' ;
12+ nginx -c ${NGINX_CONF:-/ etc/ nginx/ nginx.conf} -g ' daemon off;' 2>&1 &
13+ NGINX_PID=$!
14+
15+ echo ' Starting PHP-FPM' ;
16+ php-fpm7.0 -R -F -c ${PHP_FPM_CONF:-/ etc/ php/ 7.0/ fpm/ php-fpm.conf} 2>&1 &
17+ PHP_FPM_PID=$!
18+
19+ trap " TRAPPED_SIGNAL=true; kill -15 $NGINX_PID ; kill -15 $PHP_FPM_PID ;" SIGTERM SIGINT
20+
21+ while :
22+ do
23+ kill -0 $NGINX_PID 2> /dev/null
24+ NGINX_STATUS=$?
25+
26+ kill -0 $PHP_FPM_PID 2> /dev/null
27+ PHP_FPM_STATUS=$?
28+
29+ if [ " $TRAPPED_SIGNAL " = " false" ]; then
30+ if [ $NGINX_STATUS -ne 0 ] || [ $PHP_FPM_STATUS -ne 0 ]; then
31+ if [ $NGINX_STATUS -eq 0 ]; then
32+ kill -15 $NGINX_PID ;
33+ wait $NGINX_PID ;
34+ fi
35+ if [ $PHP_FPM_STATUS -eq 0 ]; then
36+ kill -15 $PHP_FPM_PID ;
37+ wait $PHP_FPM_PID ;
38+ fi
39+
40+ exit 1;
41+ fi
42+ else
43+ if [ $NGINX_STATUS -ne 0 ] && [ $PHP_FPM_STATUS -ne 0 ]; then
44+ exit 0;
45+ fi
46+ fi
47+
48+ sleep 1
49+ done
You can’t perform that action at this time.
0 commit comments