Update nginx.conf
Browse files- nginx.conf +20 -31
nginx.conf
CHANGED
@@ -9,51 +9,40 @@ server {
|
|
9 |
scgi_temp_path /tmp/scgi_temp 1 2;
|
10 |
|
11 |
access_log /dev/stdout;
|
12 |
-
error_log /dev/stderr info;
|
13 |
|
14 |
location / {
|
15 |
-
|
|
|
16 |
|
17 |
-
#
|
18 |
-
proxy_set_header Host
|
|
|
|
|
19 |
proxy_set_header X-Real-IP $remote_addr;
|
20 |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
21 |
proxy_set_header X-Forwarded-Proto $scheme;
|
22 |
-
|
23 |
-
# 1. 设置一个常见的浏览器 User-Agent
|
24 |
proxy_set_header User-Agent "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36";
|
25 |
-
|
26 |
-
# 2. 设置常见的 Accept 头
|
27 |
proxy_set_header Accept "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9";
|
28 |
-
proxy_set_header Accept-Language "en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7";
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
#
|
33 |
-
proxy_set_header Accept-Encoding "";
|
34 |
-
# 或者,如果你想尝试让Nginx处理压缩:
|
35 |
-
# proxy_set_header Accept-Encoding "gzip, deflate, br"; # 但这可能与后端冲突
|
36 |
-
|
37 |
-
# 4. 其他可能相关的头部
|
38 |
-
proxy_set_header Upgrade-Insecure-Requests "1"; # 告诉服务器客户端支持从http升级到https
|
39 |
-
proxy_set_header DNT "1"; # Do Not Track
|
40 |
-
# proxy_set_header Referer ""; # 之前已经有了,可以保留或根据情况设置
|
41 |
|
42 |
proxy_buffering off;
|
43 |
|
44 |
proxy_ssl_server_name on;
|
45 |
proxy_ssl_protocols TLSv1.2 TLSv1.3;
|
46 |
|
47 |
-
proxy_redirect
|
48 |
-
proxy_redirect ~^
|
49 |
-
|
50 |
-
|
|
|
51 |
|
52 |
-
|
53 |
-
#
|
54 |
-
#
|
55 |
-
# location = /cloudflare_blocked.html {
|
56 |
-
# return 200 "This site is protected by Cloudflare and the proxy request was blocked.";
|
57 |
-
# }
|
58 |
}
|
59 |
}
|
|
|
9 |
scgi_temp_path /tmp/scgi_temp 1 2;
|
10 |
|
11 |
access_log /dev/stdout;
|
12 |
+
error_log /dev/stderr info; # 保持 info 级别,方便观察
|
13 |
|
14 |
location / {
|
15 |
+
# 1. 更改代理目标为 huggingface.co (HTTPS)
|
16 |
+
proxy_pass https://huggingface.co;
|
17 |
|
18 |
+
# 2. 更新 Host 头部以匹配新的目标
|
19 |
+
proxy_set_header Host huggingface.co;
|
20 |
+
|
21 |
+
# --- 保持之前尝试的浏览器伪装头部 ---
|
22 |
proxy_set_header X-Real-IP $remote_addr;
|
23 |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
24 |
proxy_set_header X-Forwarded-Proto $scheme;
|
|
|
|
|
25 |
proxy_set_header User-Agent "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36";
|
|
|
|
|
26 |
proxy_set_header Accept "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9";
|
27 |
+
proxy_set_header Accept-Language "en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7";
|
28 |
+
proxy_set_header Accept-Encoding ""; # 保持清空,让后端决定
|
29 |
+
proxy_set_header Upgrade-Insecure-Requests "1";
|
30 |
+
proxy_set_header DNT "1";
|
31 |
+
# proxy_set_header Referer ""; # 可以清空 Referer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
proxy_buffering off;
|
34 |
|
35 |
proxy_ssl_server_name on;
|
36 |
proxy_ssl_protocols TLSv1.2 TLSv1.3;
|
37 |
|
38 |
+
# 3. 更新 proxy_redirect 和 proxy_cookie_domain 以匹配新的目标
|
39 |
+
proxy_redirect ~^https://(www\.)?huggingface\.co(?<path>.*)$ https://$host${path};
|
40 |
+
# 对于 huggingface.co,可能不需要处理 http 的重定向,因为它应该是全站 HTTPS
|
41 |
+
# 但为了通用性,可以保留:
|
42 |
+
proxy_redirect ~^http://(www\.)?huggingface\.co(?<path>.*)$ https://$host${path};
|
43 |
|
44 |
+
proxy_cookie_domain huggingface.co $host;
|
45 |
+
# huggingface.co 的 Cookie path 可能比较复杂,如果遇到登录等问题,可能需要进一步调整
|
46 |
+
# proxy_cookie_path /some_specific_path/ /;
|
|
|
|
|
|
|
47 |
}
|
48 |
}
|