0

I am trying to run an open source cloud project described here. I want to use an AWS RDS Aurora instance, instead of the project's default database, so I followed their instructions to do that here.

However, when I reload the server:

bash ~/cloud_station_deployment/reload_server.sh

and go to my website's URL, I get a 502 Bad Gateway error with Nginx:

502 gateway error

How should I solve this error?


EDIT: nginx.conf:

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    server_names_hash_bucket_size 164;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;

    server {

        # add here the ip address of your server
        # or a domain pointing to that ip (like example.com or www.example.com)
        server_name ec2-52-203-10-77.compute-1.amazonaws.com;

        keepalive_timeout 5;
        client_max_body_size 4G;

        access_log /home/ubuntu/logs/nginx-access.log;
        error_log /home/ubuntu/logs/nginx-error.log;


        location / {
            try_files $uri @proxy_to_app;
        }
    
        location /static/ {
        root /home/ubuntu/cloud_station_web/;
        autoindex off;
        }


        location @proxy_to_app {
        proxy_pass http://0.0.0.0:8001;

            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";

            proxy_redirect off;
            proxy_set_header Host $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-Host $server_name;
        }

    }    
}

This is what I tried to find the cause of the problem:

sudo systemctl status nginx

output:

● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2022-09-30 19:32:21 UTC; 2h 23min ago
     Docs: man:nginx(8)
 Main PID: 2532 (nginx)
    Tasks: 2 (limit: 1140)
   CGroup: /system.slice/nginx.service
           ├─2532 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
           └─3174 nginx: worker process

Sep 30 19:32:20 ip-172-31-83-16 systemd[1]: Stopped A high performance web server and a reverse proxy server.
Sep 30 19:32:20 ip-172-31-83-16 systemd[1]: Starting A high performance web server and a reverse proxy server...
Sep 30 19:32:21 ip-172-31-83-16 systemd[1]: nginx.service: Failed to parse PID from file /run/nginx.pid: Invalid argument
Sep 30 19:32:21 ip-172-31-83-16 systemd[1]: Started A high performance web server and a reverse proxy server.
Sep 30 19:32:36 ip-172-31-83-16 systemd[1]: Reloading A high performance web server and a reverse proxy server.
Sep 30 19:32:36 ip-172-31-83-16 systemd[1]: Reloaded A high performance web server and a reverse proxy server.

sudo systemctl status daphne

output:

● daphne.service - CloudStation Daphne
   Loaded: loaded (/etc/systemd/system/daphne.service; disabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Fri 2022-09-30 19:55:27 UTC; 24s ago
  Process: 3712 ExecStart=/home/ubuntu/ENV/bin/daphne -b 0.0.0.0 -p 8001 webgms.asgi:application (code=exited, status=1/FAILURE)
 Main PID: 3712 (code=exited, status=1/FAILURE)

Sep 30 19:55:26 ip-172-31-83-16 systemd[1]: daphne.service: Main process exited, code=exited, status=1/FAILURE
Sep 30 19:55:26 ip-172-31-83-16 systemd[1]: daphne.service: Failed with result 'exit-code'.
Sep 30 19:55:27 ip-172-31-83-16 systemd[1]: daphne.service: Service hold-off time over, scheduling restart.
Sep 30 19:55:27 ip-172-31-83-16 systemd[1]: daphne.service: Scheduled restart job, restart counter is at 5.
Sep 30 19:55:27 ip-172-31-83-16 systemd[1]: Stopped CloudStation Daphne.
Sep 30 19:55:27 ip-172-31-83-16 systemd[1]: daphne.service: Start request repeated too quickly.
Sep 30 19:55:27 ip-172-31-83-16 systemd[1]: daphne.service: Failed with result 'exit-code'.
Sep 30 19:55:27 ip-172-31-83-16 systemd[1]: Failed to start CloudStation Daphne.

Then I tried looking at the Nginx error log in ~/logs/nginx-error.log:

cat ~/logs/nginx-error.log

output:

2022/09/30 20:54:25 [error] 3174#3174: *28 connect() failed (111: Connection refused) while connecting to upstream, client: 24.130.137.133, server: ec2-52-203-10-77.compute-1.amazonaws.com, request: "GET /flightmonitor/ HTTP/1.1", upstream: "http://0.0.0.0:8001/flightmonitor/", host: "ec2-52-203-10-77.compute-1.amazonaws.com"

This makes me think the problem is related to Daphne not starting?

I also tried restarting the services, but that didn't work:

sudo systemctl daemon-reload
sudo systemctl restart nginx.service
sudo systemctl restart daphne.service

The 502 error stays and Daphne still says failed.

Other info: the server is an AWS EC2 Ubuntu 18.04 instance, and the AWS RDS instance is db.t3.small with public access. The error only happens after I follow the steps to use AWS RDS.

0 Answers0