不多逼逼直接,抄作业
location / {
proxy_pass http://172.17.0.1:7860;
proxy_set_header X-Real-IP $remote_addr;
proxy_connect_timeout 600s;
proxy_send_timeout 600s;
proxy_read_timeout 600s;
if ($http_origin ~* "http://localhost:3000") {
add_header "Access-Control-Allow-Origin" "http://localhost:3000";
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
}
if ($http_origin ~* "https://qr.zzfw.cc") {
add_header "Access-Control-Allow-Origin" "https://qr.zzfw.cc";
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
}
if ($request_method = 'OPTIONS') {
add_header "Access-Control-Allow-Origin" *;
add_header "Access-Control-Allow-Methods" "GET, POST, OPTIONS, HEAD";
add_header "Access-Control-Allow-Headers" "Authorization, Origin, X-Requested-With, Content-Type, Accept";
return 200;
}
}
测试跨域的命令
curl -s -D - -H "Origin: https://qr.zzfw.cc" https://sdwebui.zzfw.cc/ -o /dev/null -X POST
参考教程:
https://medium.com/@hariomvashisth/cors-on-nginx-be38dd0e19df