Replace Unit configuration with Nginx + PHP-FPM setup in Docker
- Remove outdated Unit-based Docker configuration and scripts. - Introduce Nginx + PHP-FPM stack with environment-based configurations. - Add custom Nginx setup for frontend-backend routing. - Update Dockerfiles, Docker Compose, and related scripts for new architecture.
This commit is contained in:
15 files changed
+293
-375
No files matched your search
@@ -0,0 +1,31 @@
|
||||
FROM docker.io/nginx:1.31-alpine AS build
|
||||
|
||||
COPY docker/web/conf/default.conf.template /etc/nginx/templates/default.conf.template
|
||||
COPY docker/web/conf/fastcgi_params /etc/nginx/fastcgi_params
|
||||
COPY docker/web/start.sh /usr/local/bin/start
|
||||
|
||||
RUN chmod 755 /usr/local/bin/start
|
||||
|
||||
FROM build AS app_build_for_production
|
||||
|
||||
WORKDIR /home/app
|
||||
COPY application /home/app
|
||||
|
||||
RUN apk --no-cache add git nodejs npm \
|
||||
&& npm install && npm run build \
|
||||
&& rm -rf /home/app/node_modules
|
||||
|
||||
FROM build AS production
|
||||
|
||||
COPY --from=app_build_for_production /home/app/public /usr/share/nginx/html
|
||||
|
||||
WORKDIR /usr/share/nginx/html
|
||||
|
||||
EXPOSE 80
|
||||
CMD ["/usr/local/bin/start"]
|
||||
|
||||
FROM build AS develop
|
||||
WORKDIR /usr/share/nginx/html
|
||||
|
||||
EXPOSE 80
|
||||
CMD ["/usr/local/bin/start"]
|
||||
@@ -0,0 +1,3 @@
|
||||
application/public/*.php
|
||||
application/public/**/*.php
|
||||
application/public/.htaccess
|
||||
@@ -0,0 +1,44 @@
|
||||
map $FRONTEND_PORT $host_with_port {
|
||||
"" $host;
|
||||
default "$host:$FRONTEND_PORT";
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80 default_server;
|
||||
listen [::]:80 default_server;
|
||||
|
||||
client_max_body_size ${NGINX_CLIENT_MAX_BODY_SIZE};
|
||||
|
||||
disable_symlinks if_not_owner from=/usr/share/nginx/html;
|
||||
|
||||
index index.php index.html;
|
||||
root /usr/share/nginx/html;
|
||||
|
||||
${GZIP_BLOCK}
|
||||
${REAL_IP_BLOCK}
|
||||
|
||||
location / {
|
||||
location / {
|
||||
try_files $uri @fallback;
|
||||
}
|
||||
location ~ \.php$ {
|
||||
return 404;
|
||||
}
|
||||
location ~ /\. {
|
||||
return 404;
|
||||
}
|
||||
location ~ /\.(ht|svn|git) {
|
||||
return 404;
|
||||
}
|
||||
}
|
||||
|
||||
location @fallback {
|
||||
fastcgi_pass ${BACKEND_HOST}:${BACKEND_PORT};
|
||||
fastcgi_index index.php;
|
||||
fastcgi_param REDIRECT_STATUS 200;
|
||||
fastcgi_param SCRIPT_FILENAME /var/www/html/public/index.php;
|
||||
fastcgi_param SCRIPT_NAME /index.php;
|
||||
fastcgi_param HTTP_HOST $host_with_port;
|
||||
include /etc/nginx/fastcgi_params;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
fastcgi_param QUERY_STRING $query_string;
|
||||
fastcgi_param REQUEST_METHOD $request_method;
|
||||
fastcgi_param CONTENT_TYPE $content_type;
|
||||
fastcgi_param CONTENT_LENGTH $content_length;
|
||||
|
||||
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
|
||||
fastcgi_param REQUEST_URI $request_uri;
|
||||
fastcgi_param DOCUMENT_URI $document_uri;
|
||||
fastcgi_param DOCUMENT_ROOT $document_root;
|
||||
fastcgi_param SERVER_PROTOCOL $server_protocol;
|
||||
fastcgi_param HTTPS $https if_not_empty;
|
||||
|
||||
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
|
||||
fastcgi_param SERVER_SOFTWARE nginx;
|
||||
|
||||
fastcgi_param REMOTE_ADDR $remote_addr;
|
||||
fastcgi_param REMOTE_PORT $remote_port;
|
||||
fastcgi_param SERVER_ADDR $server_addr;
|
||||
fastcgi_param SERVER_PORT $server_port;
|
||||
fastcgi_param SERVER_NAME $server_name;
|
||||
|
||||
fastcgi_param HTTP_X_FORWARDED_FOR $proxy_add_x_forwarded_for;
|
||||
fastcgi_param HTTP_X_REAL_IP $remote_addr;
|
||||
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
if [ "$IS_GZIP" = "1" ]; then
|
||||
GZIP_BLOCK='gzip on;
|
||||
gzip_vary on;
|
||||
gzip_proxied any;
|
||||
gzip_comp_level 6;
|
||||
gzip_buffers 16 8k;
|
||||
gzip_http_version 1.1;
|
||||
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
|
||||
gzip_min_length 1024;'
|
||||
else
|
||||
GZIP_BLOCK=''
|
||||
fi
|
||||
export GZIP_BLOCK
|
||||
|
||||
if [ -n "$TRUSTED_PROXY_CIDR" ]; then
|
||||
REAL_IP_BLOCK="set_real_ip_from $TRUSTED_PROXY_CIDR;
|
||||
real_ip_header X-Forwarded-For;
|
||||
real_ip_recursive on;"
|
||||
else
|
||||
REAL_IP_BLOCK=""
|
||||
fi
|
||||
export REAL_IP_BLOCK
|
||||
|
||||
export BACKEND_HOST="${BACKEND_HOST:-app}"
|
||||
export BACKEND_PORT="${BACKEND_PORT:-9000}"
|
||||
export FRONTEND_PORT="${FRONTEND_PORT:-''}"
|
||||
export NGINX_CLIENT_MAX_BODY_SIZE="${NGINX_CLIENT_MAX_BODY_SIZE:-'20m'}"
|
||||
|
||||
envsubst '$BACKEND_HOST $BACKEND_PORT $GZIP_BLOCK $REAL_IP_BLOCK $FRONTEND_PORT $NGINX_CLIENT_MAX_BODY_SIZE' \
|
||||
< /etc/nginx/templates/default.conf.template \
|
||||
> /etc/nginx/conf.d/default.conf
|
||||
|
||||
exec nginx -g 'daemon off;'
|
||||
Reference in new issue
Block a user