Skip to content

Commit 5ae63aa

Browse files
committed
fix: nginx config
1 parent 17b6a76 commit 5ae63aa

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

templates/nginx.conf.template

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
user privoxy;
2-
31
worker_processes auto;
42

53
events {
@@ -36,10 +34,6 @@ http {
3634
# HSTS (ngx_http_headers_module is required) (63072000 seconds)
3735
add_header Strict-Transport-Security "max-age=63072000" always;
3836

39-
# comply with Content Security policy
40-
add_header Content-Type "text/css";
41-
add_header X-Content-Type-Options nosniff;
42-
4337
#root = --webDir parameter value
4438
root /usr/local/etc/adblock2privoxy/css;
4539

@@ -59,19 +53,25 @@ http {
5953
}
6054

6155
location ~ ^/+(ab2p(?:\.common)?\.css) {
62-
# ab2p.css in top-level directory
63-
try_files $uri $1;
56+
# ab2p.css in top-level directory
57+
default_type text/css;
58+
add_header X-Content-Type-Options nosniff;
59+
try_files $uri $1;
6460
}
6561

6662
location ~ ^/[^/.]+\..+/ab2p\.css$ {
67-
# first reverse domain names order
68-
rewrite ^/([^/]*?)\.([^/.]+)(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?/ab2p.css$ /$9/$8/$7/$6/$5/$4/$3/$2/$1/ab2p.css last;
63+
# first reverse domain names order
64+
default_type text/css;
65+
add_header X-Content-Type-Options nosniff;
66+
rewrite ^/([^/]*?)\.([^/.]+)(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?(?:\.([^/.]+))?/ab2p.css$ /$9/$8/$7/$6/$5/$4/$3/$2/$1/ab2p.css last;
6967
}
7068

7169
location ~ (^.*/+)[^/]+/+ab2p\.css {
72-
# then try to get CSS for current domain
73-
# if it is unavailable - get CSS for parent domain
74-
try_files $uri $1ab2p.css;
70+
# then try to get CSS for current domain
71+
# if it is unavailable - get CSS for parent domain
72+
default_type text/css;
73+
add_header X-Content-Type-Options nosniff;
74+
try_files $uri $1ab2p.css;
7575
}
7676
}
7777
}

tests/test_privoxy.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,37 @@ def test_https_no_adblock_filters(self):
4747
except ConnectionError:
4848
pass # 99% blocked by external software
4949

50+
def test_http_adblock_blackhole(self, docker_privoxy, make_request, env_info):
51+
resp = requests.get(f"http://{env_info['ip']}/@blackhole")
52+
assert resp.status_code == 200
53+
mime_type = resp.headers.get("Content-Type")
54+
assert mime_type == "text/html"
55+
assert "adblock2privoxy" in resp.text
56+
57+
def test_https_adblock_blackhole(self, docker_privoxy, make_request, env_info):
58+
resp = requests.get(
59+
f"https://{env_info['ip']}/@blackhole",
60+
verify="./tests/privoxy-ca-bundle.crt",
61+
)
62+
assert resp.status_code == 200
63+
mime_type = resp.headers.get("Content-Type")
64+
assert mime_type == "text/html"
65+
assert "adblock2privoxy" in resp.text
66+
5067
def test_http_adblock_css_filters(self, docker_privoxy, make_request, env_info):
5168
resp = requests.get(f"http://{env_info['ip']}/ab2p.common.css")
5269
assert resp.status_code == 200
70+
mime_type = resp.headers.get("Content-Type")
71+
assert mime_type == "text/css"
5372

5473
def test_https_adblock_css_filters(self, docker_privoxy, make_request, env_info):
5574
resp = requests.get(
5675
f"https://{env_info['ip']}/ab2p.common.css",
5776
verify="./tests/privoxy-ca-bundle.crt",
5877
)
5978
assert resp.status_code == 200
79+
mime_type = resp.headers.get("Content-Type")
80+
assert mime_type == "text/css"
6081

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

0 commit comments

Comments
 (0)