-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnginx.conf
More file actions
232 lines (195 loc) · 9.16 KB
/
nginx.conf
File metadata and controls
232 lines (195 loc) · 9.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
server {
listen 7000;
server_name 101.32.9.93;
charset utf-8;
# 允许处理大型URL参数
large_client_header_buffers 8 64k;
client_header_buffer_size 32k;
client_max_body_size 20m;
client_body_buffer_size 512k;
# 静态文件目录
location / {
alias /www/wwwroot/xmoe-ui/dist/;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
# API代理
location /sk-api/ {
proxy_pass http://api.xmoe.asia/;
proxy_set_header x-forwarded-for $remote_addr;
# 添加CORS头
add_header Access-Control-Allow-Origin '*';
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization';
# 添加OPTIONS请求处理
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
}
# 特殊处理@格式链接 - 最高优先级
location ~ "^/@https://xmoe.video/validate" {
# 从URL中提取链接参数
if ($request_uri ~ "^/@https://xmoe.video/validate\?link=([^&]*)") {
set $linkparam $1;
}
# 直接代理至目标网站并带上提取的参数
proxy_pass "https://xmoe.video/validate?link=$linkparam";
# 关键请求头
proxy_set_header Host xmoe.video;
proxy_set_header Origin https://xmoe.video;
proxy_set_header Referer https://xmoe.video/;
proxy_set_header User-Agent $http_user_agent;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# HTTP版本和连接设置
proxy_http_version 1.1;
proxy_set_header Connection "keep-alive";
# 超时设置
proxy_connect_timeout 120s;
proxy_read_timeout 180s;
proxy_send_timeout 180s;
# 缓冲区设置
proxy_buffer_size 1024k;
proxy_buffers 16 512k;
proxy_busy_buffers_size 1024k;
proxy_temp_file_write_size 1024k;
# 禁用缓存
proxy_no_cache 1;
proxy_cache_bypass 1;
# CORS头
add_header Access-Control-Allow-Origin '*' always;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS' always;
add_header Access-Control-Allow-Headers 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always;
# OPTIONS请求处理
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always;
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
}
# 特殊处理validate路径 - 先匹配这个,优先级高于通用视频代理
location ^~ /video-proxy/validate {
# 精确提取link参数并解码
if ($args ~ "link=([^&]*)") {
set $link $1;
}
# 完整路径代理 - 使用变量传递参数
proxy_pass "https://xmoe.video/validate?link=$link";
# 关键请求头
proxy_set_header Host xmoe.video;
proxy_set_header Origin https://xmoe.video;
proxy_set_header Referer https://xmoe.video/;
proxy_set_header User-Agent $http_user_agent;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# 解决504超时问题 - 增加超时时间
proxy_connect_timeout 120s;
proxy_read_timeout 180s;
proxy_send_timeout 180s;
# 增加缓冲区设置
proxy_buffer_size 1024k;
proxy_buffers 16 512k;
proxy_busy_buffers_size 1024k;
proxy_temp_file_write_size 1024k;
# 禁用缓存
proxy_no_cache 1;
proxy_cache_bypass 1;
# HTTP版本和连接设置
proxy_http_version 1.1;
proxy_set_header Connection "keep-alive";
# CORS头 - 确保在代理返回前添加
add_header Access-Control-Allow-Origin '*' always;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS' always;
add_header Access-Control-Allow-Headers 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always;
# 添加OPTIONS请求处理
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always;
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
}
# 通用视频代理
location /video-proxy/ {
# 提取路径
rewrite ^/video-proxy/(.*) /$1 break;
proxy_pass https://xmoe.video;
# 完整的请求头设置
proxy_set_header Host xmoe.video;
proxy_set_header Origin https://xmoe.video;
proxy_set_header Referer https://xmoe.video/;
proxy_set_header User-Agent $http_user_agent;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# HTTP版本和连接设置
proxy_http_version 1.1;
proxy_set_header Connection "keep-alive";
# 超时设置增加
proxy_connect_timeout 60s;
proxy_read_timeout 180s;
proxy_send_timeout 120s;
# 缓冲区设置
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_temp_file_write_size 256k;
# CORS头 - 确保在代理返回前添加
add_header Access-Control-Allow-Origin '*' always;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS' always;
add_header Access-Control-Allow-Headers 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always;
# 添加OPTIONS请求处理
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always;
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
}
# 通用CORS代理
location /cors-proxy {
# 提取请求的URL
set $target_url $arg_url;
# 代理到目标URL
proxy_pass $target_url;
# 设置代理头
proxy_set_header User-Agent $http_user_agent;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Accept-Encoding "";
# HTTP版本和连接设置
proxy_http_version 1.1;
proxy_set_header Connection "keep-alive";
# 超时设置
proxy_connect_timeout 60s;
proxy_read_timeout 60s;
proxy_send_timeout 60s;
# CORS头 - 确保在代理返回前添加
add_header Access-Control-Allow-Origin '*' always;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS' always;
add_header Access-Control-Allow-Headers 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always;
# 添加OPTIONS请求处理
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always;
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
}
}