Skip to content

Commit 612b7e1

Browse files
committed
imp: nginx config
1 parent 18fee93 commit 612b7e1

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

templates/nginx.conf.template

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ events {
1212
pid /usr/local/etc/adblock2privoxy/nginx-adblock2privoxy.pid;
1313

1414
# error_log /opt/local/var/log/nginx/error-adblock2privoxy.log warn;
15-
error_log /dev/null;
15+
error_log stderr warn;
1616

1717
http {
1818
# access_log /opt/local/var/log/nginx/access-adblock2privoxy.log;
19-
access_log /dev/null;
19+
access_log /dev/stdout;
2020

2121
# Increase client_max_body_size to handle larger requests, uncommented for clarity
2222
client_max_body_size 64M;
@@ -53,14 +53,9 @@ http {
5353
#root = --webDir parameter value
5454
root /usr/local/etc/adblock2privoxy/css;
5555

56-
# If useHTTP is set:
57-
# Ensure that http://localhost:8119/ is a legitimate (200 return code)
58-
# default page; use as iOS proxy.pac blackhole
59-
# Test with curl -I --proxy http://127.0.0.1:8119 http://www.foo.com/bar?q=snafoo
60-
location / {
61-
return 301 http://$server_name:$server_port/@blackhole?;
62-
# rewrite ^ /default.html break;
63-
}
56+
# ────────────────────────────────────────────────
57+
# Blackhole
58+
# ────────────────────────────────────────────────
6459

6560
location ~ ^/@blackhole {
6661
default_type text/html;
@@ -69,29 +64,41 @@ http {
6964
# rewrite ^ /default.html break;
7065
}
7166

67+
# ────────────────────────────────────────────────
68+
# ab2p resources
69+
# ────────────────────────────────────────────────
70+
7271
location ~ ^/+(ab2p(?:\.common)?\.css) {
7372
# ab2p.css in top-level directory
7473
default_type text/css;
75-
add_header X-Content-Type-Options nosniff;
76-
add_header Cache-Control "public, max-age=31536000, immutable";
77-
try_files $uri $1;
74+
add_header X-Content-Type-Options nosniff always;
75+
add_header Cache-Control "public, max-age=31536000, immutable" always;
76+
try_files $uri $1 =404;
7877
}
7978

8079
location ~ ^/[^/.]+\..+/ab2p\.css$ {
8180
# first reverse domain names order
8281
default_type text/css;
83-
add_header X-Content-Type-Options nosniff;
84-
add_header Cache-Control "public, max-age=31536000, immutable";
82+
add_header X-Content-Type-Options nosniff always;
83+
add_header Cache-Control "public, max-age=31536000, immutable" always;
8584
rewrite ^/([^/]*?)\.([^/.]+)(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?/ab2p.css$ /$9/$8/$7/$6/$5/$4/$3/$2/$1/ab2p.css last;
8685
}
8786

8887
location ~ (^.*/+)[^/]+/+ab2p\.css {
8988
# then try to get CSS for current domain
9089
# if it is unavailable - get CSS for parent domain
9190
default_type text/css;
92-
add_header X-Content-Type-Options nosniff;
93-
add_header Cache-Control "public, max-age=31536000, immutable";
94-
try_files $uri $1ab2p.css;
91+
add_header X-Content-Type-Options nosniff always;
92+
add_header Cache-Control "public, max-age=31536000, immutable" always;
93+
try_files $uri $1ab2p.css =404;
94+
}
95+
96+
# ────────────────────────────────────────────────
97+
# Fallback
98+
# ────────────────────────────────────────────────
99+
100+
location / {
101+
return 204;
95102
}
96103
}
97104
}

tests/test_privoxy.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ def test_http_adblock_css_filters(self, docker_privoxy, make_request, env_info):
6969
assert resp.status_code == 200
7070
mime_type = resp.headers.get("Content-Type")
7171
assert mime_type == "text/css"
72+
resp = requests.get(f"https://{env_info['ip']}/this.not.exists.css")
73+
assert resp.status_code == 204
7274

7375
def test_https_adblock_css_filters(self, docker_privoxy, make_request, env_info):
7476
resp = requests.get(
@@ -78,6 +80,11 @@ def test_https_adblock_css_filters(self, docker_privoxy, make_request, env_info)
7880
assert resp.status_code == 200
7981
mime_type = resp.headers.get("Content-Type")
8082
assert mime_type == "text/css"
83+
resp = requests.get(
84+
f"https://{env_info['ip']}/this.not.exists.css",
85+
verify="./tests/privoxy-ca-bundle.crt",
86+
)
87+
assert resp.status_code == 204
8188

8289
def test_http_privman_blocklist(self, docker_privoxy, make_request, exec_privman):
8390
resp = exec_privman(docker_privoxy, "--add-blocklist", ".google.")

0 commit comments

Comments
 (0)