现有的 nginx 配置如下。我尝试了多种方法,但都不起作用。
server {
server_name backend.xxxxxx.com www.backend.xxxxxx.com;
client_max_body_size 100M;
#add_header Access-Control-Allow-Origin *;
#add_header 'Access-Control-Allow-Origin' '*' always;
location / {
#add_header 'Access-Control-Allow-Origin' '*' always;
include proxy_params;
proxy_pass http://unix:/var/log/gunicorn/xxxxxx.sock;
# Simple requests
#if ($request_method ~* "(GET|POST)") {
#add_header "Access-Control-Allow-Origin" *;
#}
# Preflighted requests
#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;
#}
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/backend.xxxxxx.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/backend.xxxxxx.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = backend.xxxxxx.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name backend.xxxxxx.com www.backend.xxxxxx.com;
client_max_body_size 100M;
return 404; # managed by Certbot
}
在 Django 中,我已添加django-cors-headers
带所有配置的插件。需要您的专家建议。