Jump to content

Trouble configuring React+Flask Webapp using nginx and gunicorn

Sorry if this is a terrible question but I don't know where else to turn. I have spent all day trying to have gunicorn bind to 127.0.0.1. So to start from the Top. I am making a website with a React frontend and a Flask backend all of this is running on centos7. I am using Nginx to manage the traffic I have it set up for SSL. I am using gunicorn to run Flask for production. Currently, I have this working where I have Nginx routing the traffic to React and then having the requests sent to gunicorn bound on 0.0.0.0:8000. In order to get this to work, I had to use 2 certificates one for each port. I was reading that binding gunicorn to an internal port would make it so I don't need the second certificate. When I try and run gunicorn with out the certs bound to localhost i get this error from React. 

 

Error: Network Error followed by ERR_CONNECTION_REFUSED to 127.0.0.1:8000/auth/login

 

I have CORS enabled on the flask end and I'm using Blueprints. Here is my Nginx configurations

server {
        listen 80;
        listen [::]:80;
        server_name my_server_name;
        return 301 https://$host$request_uri;
    }

server {
        listen       443 ssl http2;
        listen       [::]:443 ssl http2;
        server_name  my_server_name;

        ssl_certificate "/etc/nginx/nginx-selfsigned.crt";
        ssl_certificate_key "/etc/nginx/private/nginx-selfsigned.key";
        ssl_dhparam "/etc/nginx/dhparam.pem";
        ssl_protocols TLSv1.2;
        ssl_ciphers "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384";
        ssl_prefer_server_ciphers on;
        ssl_session_tickets off;
        ssl_stapling on;
        ssl_stapling_verify on;
        proxy_set_header HOST $http_host;
        proxy_set_header X-REAL-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        #proxy_set_header X-Forwarded-Proto $scheme;
        location / {
             proxy_pass "http://127.0.0.1:8080/";
             proxy_http_version 1.1;
             proxy_set_header Upgrade $http_upgrade;
             proxy_set_header Connection "upgrade";
        }

        location /api/ {
            proxy_pass http://127.0.0.1:8000/;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        }

        location /auth/ {
            proxy_pass http://127.0.0.1:8000/;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }

    }

Any help would be greatly appreciated.
 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×