Skip to content

Commit 6a3d751

Browse files
authored
Tweak nginx config (#1769)
1 parent fcf8142 commit 6a3d751

File tree

5 files changed

+22
-2
lines changed

5 files changed

+22
-2
lines changed

docker-compose.prod.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ services:
5454
volumes:
5555
# repo files
5656
- ./nginx/production.conf:/etc/nginx/conf.d/default.conf:ro
57+
- ./nginx/geo.conf:/etc/nginx/conf.d/geo.conf:ro
5758
- ./frontend/down.html:/var/www/decomp.me/down.html:ro
5859
# certbot
5960
- ./certbot:/var/www/certbot

docker-compose.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,6 @@ services:
5252
- "80:80"
5353
volumes:
5454
- ./nginx/development.conf:/etc/nginx/conf.d/default.conf:ro
55+
- ./nginx/geo.conf:/etc/nginx/conf.d/geo.conf:ro
5556
- ./frontend/down.html:/var/www/down.html:ro
5657
- ./backend/media:/media

nginx/development.conf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# nginx config file used by docker
1+
include /etc/nginx/conf.d/geo.conf;
22

33
server {
44
listen 80;
@@ -10,6 +10,10 @@ server {
1010

1111
server_name decomp.local www.decomp.local;
1212

13+
if ($is_denied) {
14+
return 403;
15+
}
16+
1317
location / {
1418
try_files $uri @proxy_frontend;
1519
}

nginx/geo.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
geo $is_denied {
2+
default 0;
3+
}

nginx/production.conf

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
include /etc/nginx/conf.d/geo.conf;
2+
13
server {
24
listen 80;
35
server_name decomp.me www.decomp.me;
@@ -12,7 +14,7 @@ server {
1214
}
1315

1416
log_format latency_log escape=json
15-
'{ "cf_ip":"$http_cf_connecting_ip", "remote":"$remote_addr", '
17+
'{ "cf_edge_ip":"$cf_edge_ip", "remote":"$remote_addr", '
1618
'"time":"$time_iso8601", "request":"$request", "status":$status, '
1719
'"bytes":$body_bytes_sent, "referer":"$http_referer", "agent":"$http_user_agent", '
1820
'"rt":$request_time, "urt":"$upstream_response_time", '
@@ -51,6 +53,11 @@ server {
5153
include /etc/letsencrypt/options-ssl-nginx.conf;
5254
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
5355

56+
# Cloudflare
57+
set $cf_edge_ip $remote_addr;
58+
real_ip_header CF-Connecting-IP;
59+
real_ip_recursive on;
60+
5461
# Compression
5562
gzip on;
5663
gzip_static on;
@@ -78,6 +85,10 @@ server {
7885
text/plain
7986
text/xml;
8087

88+
if ($is_denied) {
89+
return 403;
90+
}
91+
8192
location / {
8293
try_files /dummy.html @proxy_frontend;
8394
}

0 commit comments

Comments
 (0)