Score:1

CORS is not working NGINX + DJANGO + REACT application

cn flag

Existing nginx configuration given bellow. I tried in multiple way but nothing is working.

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


}

In Django I have added django-cors-headers plugin with all configuration. Need your expert suggestion.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.