Skip to content

Commit b4d4e25

Browse files
nginx only pass correct request
1 parent 8e85a7b commit b4d4e25

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

backend/nginx/api.conf

+18-11
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,32 @@ server {
66
return 444;
77
}
88

9-
# Only allow specific HTTP methods
10-
if ($request_method !~ ^(GET|POST|OPTIONS)$) {
9+
# Only allow specific paths with specific methods
10+
location ~ ^/(generate(/cost)?|modify)$ {
11+
12+
# Only allow specific methods
13+
if ($request_method !~ ^(GET|POST|OPTIONS)$) {
14+
return 444;
15+
}
16+
17+
proxy_pass http://127.0.0.1:8000;
18+
include proxy_params;
19+
proxy_redirect off;
20+
}
21+
22+
# Return 444 for all other requests
23+
location / {
1124
return 444;
1225
}
1326

14-
# Block these requests BEFORE the location / block
15-
location = /favicon.ico {
27+
# Block common web crawling targets
28+
location = /favicon.ico {
1629
return 404;
1730
access_log off;
1831
log_not_found off;
1932
}
2033

21-
location = /robots.txt {
34+
location = /robots.txt {
2235
return 404;
2336
access_log off;
2437
log_not_found off;
@@ -31,12 +44,6 @@ server {
3144
log_not_found off;
3245
}
3346

34-
location / {
35-
proxy_pass http://127.0.0.1:8000;
36-
include proxy_params;
37-
proxy_redirect off;
38-
}
39-
4047
# Add timeout settings
4148
proxy_connect_timeout 300;
4249
proxy_send_timeout 300;

0 commit comments

Comments
 (0)