Added nginx to server static content when app is in container

This commit is contained in:
Deon George 2020-03-11 14:43:15 +11:00
parent e87698b30c
commit c8cc79dbb3
3 changed files with 53 additions and 2 deletions

View File

@ -3,7 +3,8 @@
FROM php:7.3-fpm FROM php:7.3-fpm
RUN apt-get update && apt-get install -y openssh-server unzip git msmtp \ RUN apt-get update && apt-get install -y openssh-server unzip git msmtp nginx \
&& rm /etc/nginx/sites-enabled/default \
&& apt-get -y autoremove \ && apt-get -y autoremove \
&& apt-get clean \ && apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
@ -11,6 +12,7 @@ RUN apt-get update && apt-get install -y openssh-server unzip git msmtp \
RUN useradd -c "Hosting Admin User" -u 1000 -g users -G www-data -d /var/www/html -M lamp RUN useradd -c "Hosting Admin User" -u 1000 -g users -G www-data -d /var/www/html -M lamp
RUN sed -e 's/^expose_php = On/expose_php = Off/' /usr/local/etc/php/php.ini-production > /usr/local/etc/php/php.ini RUN sed -e 's/^expose_php = On/expose_php = Off/' /usr/local/etc/php/php.ini-production > /usr/local/etc/php/php.ini
COPY www.conf /usr/local/etc/php-fpm.d/ COPY www.conf /usr/local/etc/php-fpm.d/
COPY nginx-app.conf /etc/nginx/conf.d/
COPY sshd_config.patch /tmp/ COPY sshd_config.patch /tmp/
RUN (cd / && patch -p0 ) < /tmp/sshd_config.patch && rm /tmp/sshd_config.patch RUN (cd / && patch -p0 ) < /tmp/sshd_config.patch && rm /tmp/sshd_config.patch
@ -18,7 +20,7 @@ RUN (cd / && patch -p0 ) < /tmp/sshd_config.patch && rm /tmp/sshd_config.patch
COPY msmtprc /etc/ COPY msmtprc /etc/
RUN sed -i -e 's#^;sendmail_path =#sendmail_path = "/usr/bin/msmtp -t"#' /usr/local/etc/php/php.ini RUN sed -i -e 's#^;sendmail_path =#sendmail_path = "/usr/bin/msmtp -t"#' /usr/local/etc/php/php.ini
EXPOSE 9000/tcp 22/tcp EXPOSE 22/tcp
# Add composer # Add composer
RUN curl https://getcomposer.org/installer|php -- --install-dir=/usr/local/bin --filename=composer RUN curl https://getcomposer.org/installer|php -- --install-dir=/usr/local/bin --filename=composer

14
init
View File

@ -5,6 +5,8 @@ role=${CONTAINER_ROLE:-app}
env=${APP_ENV:-live} env=${APP_ENV:-live}
php=${PHP_DIR:-/var/www/html} php=${PHP_DIR:-/var/www/html}
composer=${COMPOSER_DIR:-/var/www/.composer} composer=${COMPOSER_DIR:-/var/www/.composer}
NO_NGINX=${NO_NGINX:-TRUE}
SSH_START=${SSH_START:-FALSE}
function mp() { function mp() {
set +e set +e
@ -14,6 +16,14 @@ function mp() {
echo ${mp} echo ${mp}
} }
function nginx_start() {
# Start NGINX
if [ -x /usr/sbin/nginx -a "${NO_NGINX}" != "TRUE" ]; then
echo "* Starting NGINX..."
start-stop-daemon --start --pidfile /var/run/nginx.pid --exec /usr/sbin/nginx -- -g 'daemon on; master_process on;'
fi
}
# General Setup # General Setup
if [ -x /usr/sbin/sshd -a "${SSH_START}" = "TRUE" ]; then if [ -x /usr/sbin/sshd -a "${SSH_START}" = "TRUE" ]; then
[ ! -d /var/run/sshd ] && mkdir /var/run/sshd [ ! -d /var/run/sshd ] && mkdir /var/run/sshd
@ -79,6 +89,8 @@ if [ "${role}" = "app" -a -e artisan ]; then
fi fi
fi fi
nginx_start
exec /usr/local/bin/docker-php-entrypoint "$@" exec /usr/local/bin/docker-php-entrypoint "$@"
elif [ "$role" = "queue" -a -e artisan ]; then elif [ "$role" = "queue" -a -e artisan ]; then
@ -129,6 +141,8 @@ elif [ "$role" = "scheduler" -a -e artisan ]; then
" "
else else
nginx_start
echo "? NO container role \"${role}\", AND/OR no laravel install, just starting php-fpm" echo "? NO container role \"${role}\", AND/OR no laravel install, just starting php-fpm"
exec /usr/local/bin/docker-php-entrypoint "$@" exec /usr/local/bin/docker-php-entrypoint "$@"
fi fi

35
nginx-app.conf Normal file
View File

@ -0,0 +1,35 @@
server {
listen 80 default_server;
listen [::]:80 default_server;
access_log none;
client_max_body_size 10m;
error_log none;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 16k;
index index.php index.html;
root /var/www/html;
server_tokens off;
set $my_https "off";
if ($http_x_forwarded_proto = "https") {
set $my_https "on";
}
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;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SERVER_NAME $host;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param HTTPS $my_https;
fastcgi_param PHP_ADMIN_VALUE "sendmail_path=/usr/sbin/sendmail -i -t";
}
}