Skip to content

Commit 82ded75

Browse files
committed
Use a .conf file for Nginx
1 parent 70f435b commit 82ded75

File tree

2 files changed

+36
-38
lines changed

2 files changed

+36
-38
lines changed

docker/NginxDockerfile

+1-38
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,4 @@
11
FROM nginx:1.15.8
22

33
# set nginx config
4-
RUN rm /etc/nginx/conf.d/default.conf
5-
RUN { \
6-
echo 'server {'; \
7-
echo ' listen 80;'; \
8-
echo ' server_name _;'; \
9-
echo ' root /app/public;'; \
10-
echo ''; \
11-
echo ' add_header X-Content-Type-Options nosniff;'; \
12-
echo ' add_header X-XSS-Protection "1; mode=block";'; \
13-
echo ' add_header X-Frame-Options SAMEORIGIN;'; \
14-
echo ''; \
15-
echo ' if ($http_user_agent ~* "WordPress") {'; \
16-
echo ' return 403;'; \
17-
echo ' }'; \
18-
echo ''; \
19-
echo ' location / {'; \
20-
echo ' try_files $uri /index.php$is_args$args;'; \
21-
echo ' }'; \
22-
echo ''; \
23-
echo ' location /protected-files/ {'; \
24-
echo ' internal;'; \
25-
echo ' alias /app/files/;'; \
26-
echo ' }'; \
27-
echo ''; \
28-
echo ' location ~ ^/index\.php(/|$) {'; \
29-
echo ' fastcgi_pass app:9000;'; \
30-
echo ' fastcgi_split_path_info ^(.+\.php)(/.*)$;'; \
31-
echo ' include fastcgi_params;'; \
32-
echo ' fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;'; \
33-
echo ' fastcgi_param DOCUMENT_ROOT $realpath_root;'; \
34-
echo ' internal;'; \
35-
echo ' }'; \
36-
echo ''; \
37-
echo ' location ~ \.php$ {'; \
38-
echo ' return 404;'; \
39-
echo ' }'; \
40-
echo '}'; \
41-
} > /etc/nginx/conf.d/default.conf
4+
ADD nginx-default.conf /etc/nginx/conf.d/default.conf

docker/nginx-default.conf

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
server {
2+
listen 80;
3+
server_name _;
4+
root /app/public;
5+
6+
add_header X-Content-Type-Options nosniff;
7+
add_header X-XSS-Protection "1; mode=block";
8+
add_header X-Frame-Options SAMEORIGIN;
9+
10+
if ($http_user_agent ~* "WordPress") {
11+
return 403;
12+
}
13+
14+
location / {
15+
try_files $uri /index.php$is_args$args;
16+
}
17+
18+
location /protected-files/ {
19+
internal;
20+
alias /app/files/;
21+
}
22+
23+
location ~ ^/index\.php(/|$) {
24+
fastcgi_pass app:9000;
25+
fastcgi_split_path_info ^(.+\.php)(/.*)$;
26+
include fastcgi_params;
27+
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
28+
fastcgi_param DOCUMENT_ROOT $realpath_root;
29+
internal;
30+
}
31+
32+
location ~ \.php$ {
33+
return 404;
34+
}
35+
}

0 commit comments

Comments
 (0)