0

I use next.js + ec2 (Ubuntu 22.04) + s3 + codeDeploy + pm2 and github actions to deploy my application. And i also use nginx and let's encrypt to set https.

It went well until the day before yesterday. But i got this error since yesterday.

i'm struggling to find out the solution but can't get anything yet..

enter image description here

This is my error.log.

2022/11/21 05:15:48 [error] 11453#11453: *57 connect() failed (111: Unknown error) while connecting to upstream, client: 59.10.246.221, server: cocstats.awslearner-highjoon.com, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:3080/", host: "cocstats.awslearner-highjoon.com"
2022/11/21 05:15:48 [error] 11453#11453: *57 connect() failed (111: Unknown error) while connecting to upstream, client: 59.10.246.221, server: cocstats.awslearner-highjoon.com, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:3080/favicon.ico", host: "cocstats.awslearner-highjoon.com", referrer: "https://cocstats.awslearner-highjoon.com/"

I set port number as 3080 like this. (package.json)

"scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "cross-env NODE_ENV=production next start -p 3080",
    "lint": "next lint"
  },

This is my ec2 inbound rules. enter image description here

And this is my nginx config.

I thought nginx proxy buffer size was a problem, so i increased the size of the buffer and the time for timeout to be processed, but still not working...

server {
        listen 80 default_server;
        listen [::]:80 default_server;
        server_name cocstats.awslearner-highjoon.com;
        return 301 https://cocstats.awslearner-highjoon.com$request_uri;

        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

        # pass PHP scripts to FastCGI server
        #
        #location ~ \.php$ {
        #       include snippets/fastcgi-php.conf;
        #
        #       # With php-fpm (or other unix sockets):
        #       fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass 127.0.0.1:9000;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        #}
}

server {
        listen 443 ssl;
        server_name cocstats.awslearner-highjoon.com;
        ssl_certificate /etc/letsencrypt/live/cocstats.awslearner-highjoon.com/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/cocstats.awslearner-highjoon.com/privkey.pem; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
        location / {
                proxy_set_header Host $host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
                proxy_set_header X-Real-IP $remote_addr;
                proxy_pass http://127.0.0.1:3080;
                proxy_redirect off;
                proxy_buffer_size          128k;
                proxy_buffers              4 256k;
                proxy_busy_buffers_size    256k;
        }
}

Please help me...

highJoon
  • 1
  • 1
  • You did not mention, how are you running your app. YOu did write in package.json, but are you running it with 'npm run start' – Gorav Singal Nov 21 '22 at 10:07
  • My bad. I'm using yarn to run my app. so running app command is like 'sudo npx pm2 start yarn -- start' in ect instance. @GoravSingal – highJoon Nov 21 '22 at 12:37

0 Answers0