Score:0

Django Vue.js Nginx POST request ERROR 502 (Bad Gateway), when using DRF API

in flag

I have deployed Vue.js and Django E-commerce on VPS, where I set up Nginx and Gunicorn. All pages are working fine, all pages from Vue.js and the Admin area of Django. But when it comes to use forms and basically do anything related with /api/v1/ it gets ERROR 502. What could be wrong? I have no idea how to solve that and I've been having this error for over a few days. Hope you could help. Thank you!

Here is my Nginx:

upstream perulab_app_server {
    server unix:/webapps/perulab/venv/run/gunicorn.sock fail_timeout=0;
}

server {
    listen 8000;
    listen [::]:8000;
    server_name 172.16.7.52;

    client_max_body_size 40M;


    location / {
        root /webapps/perulab/web-frontend/dist;
        try_files $uri /index.html;
    }


    location /static/ {
        root /webapps/perulab/web-backend;
    }

    location /media/ {
        root /webapps/perulab/web-backend;
    }

    location /api/ {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-NginX-Proxy true;
        proxy_pass http://perulab_app_server/api/;
        proxy_ssl_session_reuse off;
        proxy_set_header Host $http_host;
        proxy_redirect off;
    }

    location /admin/ {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-NginX-Proxy true;
        proxy_pass http://perulab_app_server/admin/;
        proxy_ssl_session_reuse off;
        proxy_set_header Host $http_host;
        proxy_redirect off;
    }



}
Michael Hampton avatar
cz flag
Which software sent the 502 error?
Ivan Stepanchuk avatar
in flag
In Chrome console, when Axios is trying to access DRF api to send contact email for example or any other form. But it does show products, which is strange. @MichaelHampton
Ivan Stepanchuk avatar
in flag
I didn't wat to use subdomains, I wanted to make them use the same port. When running "gunicorn --bind 172.16.7.52:8000 core.wsgi" it says connection in use. @MichaelHampton
Michael Hampton avatar
cz flag
Do you mean that your application sent the 502 error? That seems quite odd.
Ivan Stepanchuk avatar
in flag
Yes, the page stays the same but the console returns POST http://172.16.7.52:8000/api/v1/contacto/ 502 (Bad Gateway).
Michael Hampton avatar
cz flag
Look at the response body from that request.
Ivan Stepanchuk avatar
in flag
AssertionError at /api/v1/contacto/ Expected a `Response`, `HttpResponse` or `HttpStreamingResponse` to be returned from the view, but received a `<class 'NoneType'>`, this is strange, because when on local machine it was sending just fine.
Ivan Stepanchuk avatar
in flag
@MichaelHampton It looks like some APIs work, and all of them that work they have one thing in common - they don't send emails. All the rest of APIs like contact or Password Change for example that sends an email, creates this Error 502. Still don't know how to solve that.
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.