Skip to content

Commit a2997d0

Browse files
committed
feat: unix socket, gzip, higher file uploads
1 parent e8920f2 commit a2997d0

File tree

4 files changed

+41
-15
lines changed

4 files changed

+41
-15
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
# CHANGELOG
22

3+
## 24 (2024-11-09)
4+
5+
- Run PHP-FPM over a Unix sockeet instead of TCP since Nginx and PHP-FPM run inside the same container
6+
- Enable Gzip
7+
- Bump file upload size from 5mb to 10mb
8+
39
## 23 (2024-11-25)
410

5-
Fix invalid comment in `opcache.ini` file
11+
- Fix invalid comment in `opcache.ini` file
612

713
## 22 (2024-11-25)
814

Dockerfile

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,14 @@ RUN apk add --no-cache --update \
3838
opcache \
3939
pdo_mysql \
4040
zip \
41-
# Setup Nginx directories, permissions, and one-off configurations
42-
&& mkdir -p /var/run/nginx \
43-
&& chown -R www-data:www-data /var/run/nginx /var/lib/nginx /var/log/nginx \
41+
# Setup directories and permissions
42+
&& mkdir -p /var/run/nginx /var/run/php-fpm \
43+
&& chown -R www-data:www-data /var/run/nginx /var/run/php-fpm /var/lib/nginx /var/log/nginx \
44+
# Fix Nginx configuration
4445
&& sed -i 's|ssl_protocols TLSv1.1|ssl_protocols|' /etc/nginx/nginx.conf \
4546
&& sed -i 's|user nginx;|#user www-data;|' /etc/nginx/nginx.conf \
46-
&& sed -i 's|user =|;user =|' /usr/local/etc/php-fpm.d/www.conf \
47-
&& sed -i 's|group =|;group =|' /usr/local/etc/php-fpm.d/www.conf \
48-
# Tune PHP-FPM for more throughput
49-
&& sed -i 's|pm.start_servers = 2|pm.start_servers = 4|' /usr/local/etc/php-fpm.d/www.conf \
50-
&& sed -i 's|pm.min_spare_servers = 1|pm.min_spare_servers = 2|' /usr/local/etc/php-fpm.d/www.conf \
51-
&& sed -i 's|pm.max_spare_servers = 3|pm.max_spare_servers = 8|' /usr/local/etc/php-fpm.d/www.conf \
52-
&& sed -i 's|pm.max_children = 5|pm.max_children = 16|' /usr/local/etc/php-fpm.d/www.conf \
53-
&& sed -i 's|;pm.max_requests = 500|pm.max_requests = 500|' /usr/local/etc/php-fpm.d/www.conf \
5447
# Enable Nginx stdout/stderr logging, disable php-fpm access logs
5548
&& ln -sf /dev/stdout /var/log/nginx/access.log && ln -sf /dev/stderr /var/log/nginx/error.log \
56-
&& echo "access.log = /dev/null" >> /usr/local/etc/php-fpm.d/www.conf \
5749
# Setup msmtp log
5850
&& touch /var/log/msmtp.log \
5951
&& chown www-data:www-data /var/log/msmtp.log \
@@ -63,6 +55,7 @@ RUN apk add --no-cache --update \
6355
&& rm -rf /var/cache/apk/* /tmp/*
6456

6557
COPY /config/nginx.conf /etc/nginx/http.d/default.conf
58+
COPY /config/php-fpm.conf /usr/local/etc/php-fpm.d/zz-docker.conf
6659
COPY /config/opcache.ini /usr/local/etc/php/conf.d/php-opocache-cfg.ini
6760
COPY /config/msmtp.ini /usr/local/etc/php/conf.d/php-msmtp-cfg.ini
6861
COPY /config/msmtprc /etc/msmtprc

config/nginx.conf

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,18 @@ server {
88
add_header X-Frame-Options "SAMEORIGIN";
99
add_header X-Content-Type-Options "nosniff";
1010

11-
client_max_body_size 5m;
11+
client_max_body_size 10m;
1212
client_body_buffer_size 128k;
1313
server_tokens off;
1414

15+
gzip on;
16+
gzip_comp_level 6;
17+
gzip_min_length 1000;
18+
gzip_types text/plain text/css application/javascript application/json application/xml text/javascript;
19+
gzip_proxied any;
20+
gzip_buffers 16 8k;
21+
gzip_disable "MSIE [1-6]\.";
22+
1523
location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
1624
access_log off;
1725
log_not_found off;
@@ -30,7 +38,7 @@ server {
3038

3139
location ~ \.php$ {
3240
try_files $uri =404;
33-
fastcgi_pass 127.0.0.1:9000;
41+
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
3442
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
3543
include fastcgi_params;
3644
}

config/php-fpm.conf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[global]
2+
daemonize = no
3+
4+
[www]
5+
; Have Nginx and PHP-FPM connect over a socket instead of HTTP
6+
listen = /var/run/php-fpm/php-fpm.sock
7+
listen.owner = www-data
8+
listen.group = www-data
9+
listen.mode = 0660
10+
11+
; Tune PHP-FPM for more throughput
12+
pm.start_servers = 4
13+
pm.min_spare_servers = 2
14+
pm.max_spare_servers = 8
15+
pm.max_children = 16
16+
pm.max_requests = 500
17+
18+
; Don't log PHP-FPM
19+
access.log = /dev/null

0 commit comments

Comments
 (0)