Skip to content

Commit bf2732f

Browse files
doedjeTrafeX
authored andcommitted
Chopped up nginx.conf, extracted the server block to /conf.d/default.conf as requested in #98
1 parent 15dba68 commit bf2732f

File tree

3 files changed

+61
-60
lines changed

3 files changed

+61
-60
lines changed

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ RUN apk add --no-cache \
2929
# Create symlink so programs depending on `php` still function
3030
RUN ln -s /usr/bin/php81 /usr/bin/php
3131

32-
# Configure nginx
32+
# Configure nginx - http
3333
COPY config/nginx.conf /etc/nginx/nginx.conf
34+
# Configure nginx - default server
35+
COPY config/conf.d /etc/nginx/conf.d/
3436

3537
# Configure PHP-FPM
3638
COPY config/fpm-pool.conf /etc/php81/php-fpm.d/www.conf

config/conf.d/default.conf

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Default server definition
2+
server {
3+
listen [::]:8080 default_server;
4+
listen 8080 default_server;
5+
server_name _;
6+
7+
sendfile off;
8+
tcp_nodelay on;
9+
absolute_redirect off;
10+
11+
root /var/www/html;
12+
index index.php index.html;
13+
14+
location / {
15+
# First attempt to serve request as file, then
16+
# as directory, then fall back to index.php
17+
try_files $uri $uri/ /index.php?q=$uri&$args;
18+
}
19+
20+
# Redirect server error pages to the static page /50x.html
21+
error_page 500 502 503 504 /50x.html;
22+
location = /50x.html {
23+
root /var/lib/nginx/html;
24+
}
25+
26+
# Pass the PHP scripts to PHP-FPM listening on php-fpm.sock
27+
location ~ \.php$ {
28+
try_files $uri =404;
29+
fastcgi_split_path_info ^(.+\.php)(/.+)$;
30+
fastcgi_pass unix:/run/php-fpm.sock;
31+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
32+
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
33+
fastcgi_index index.php;
34+
include fastcgi_params;
35+
}
36+
37+
location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
38+
expires 5d;
39+
}
40+
41+
# Deny access to . files, for security
42+
location ~ /\. {
43+
log_not_found off;
44+
deny all;
45+
}
46+
47+
# Allow fpm ping and status from localhost
48+
location ~ ^/(fpm-status|fpm-ping)$ {
49+
access_log off;
50+
allow 127.0.0.1;
51+
deny all;
52+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
53+
include fastcgi_params;
54+
fastcgi_pass unix:/run/php-fpm.sock;
55+
}
56+
}

config/nginx.conf

Lines changed: 2 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -28,74 +28,17 @@ http {
2828
uwsgi_temp_path /tmp/uwsgi_temp;
2929
scgi_temp_path /tmp/scgi_temp;
3030

31-
# Default server definition
32-
server {
33-
listen [::]:8080 default_server;
34-
listen 8080 default_server;
35-
server_name _;
36-
37-
sendfile off;
38-
tcp_nodelay on;
39-
absolute_redirect off;
40-
41-
root /var/www/html;
42-
index index.php index.html;
43-
44-
location / {
45-
# First attempt to serve request as file, then
46-
# as directory, then fall back to index.php
47-
try_files $uri $uri/ /index.php?q=$uri&$args;
48-
}
49-
50-
# Redirect server error pages to the static page /50x.html
51-
error_page 500 502 503 504 /50x.html;
52-
location = /50x.html {
53-
root /var/lib/nginx/html;
54-
}
55-
56-
# Pass the PHP scripts to PHP-FPM listening on php-fpm.sock
57-
location ~ \.php$ {
58-
try_files $uri =404;
59-
fastcgi_split_path_info ^(.+\.php)(/.+)$;
60-
fastcgi_pass unix:/run/php-fpm.sock;
61-
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
62-
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
63-
fastcgi_index index.php;
64-
include fastcgi_params;
65-
}
66-
67-
location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
68-
expires 5d;
69-
}
70-
71-
# Deny access to . files, for security
72-
location ~ /\. {
73-
log_not_found off;
74-
deny all;
75-
}
76-
77-
# Allow fpm ping and status from localhost
78-
location ~ ^/(fpm-status|fpm-ping)$ {
79-
access_log off;
80-
allow 127.0.0.1;
81-
deny all;
82-
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
83-
include fastcgi_params;
84-
fastcgi_pass unix:/run/php-fpm.sock;
85-
}
86-
}
87-
8831
# Hardening
8932
proxy_hide_header X-Powered-By;
9033
fastcgi_hide_header X-Powered-By;
9134
server_tokens off;
92-
35+
9336
gzip on;
9437
gzip_proxied any;
9538
gzip_types text/plain application/xml text/css text/js text/xml application/x-javascript text/javascript application/json application/xml+rss;
9639
gzip_vary on;
9740
gzip_disable "msie6";
98-
41+
9942
# Include other server configs
10043
include /etc/nginx/conf.d/*.conf;
10144
}

0 commit comments

Comments
 (0)