1

I had a MEAN site hosted on DigitalOcean, and now I moved it to an EC2 micro instance. I imported the database, set up PM2, copied all files and everything, and set up Nginx as a reverse proxy. No biggie.

When I "curl localhost", the site loads perfectly. But I can't connect to it from anywhere except localhost. For example, running "curl " on the old VPS gives a "connection timed out" error. And when I try to access the site in Chrome, it loads until a timeout error as well.

As you can imagine, I am confused. The following is my /etc/nginx/sites-available/default:

server {
    listen 80;
    server_name www.my-domain.com my-domain.com;
    return 301 https://$server_name$request_uri;
}

server {
  listen 443 default_server;
  ssl on;

  server_name  my-domain.com;
  ssl_certificate /etc/nginx/ssl/nginx.crt;
  ssl_certificate_key /etc/nginx/ssl/nginx.key;

  location / {
    proxy_pass http://localhost:3000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
  }

}

Is there something I am missing here? Thanks again, just very new to AWS, and a bit confused.

  • And how long have you waited for DNS changes to take effect? – Simon Hayter Jun 17 '16 at 18:26
  • Haven't changed the DNS yet, I'm trying to connect via the actual IP, just to make sure things are working. – Tobe O Jun 17 '16 at 18:29
  • Then you can't use server_name www.my-domain.com my-domain.com; in your virtual host, since your not telling it to use an IP address. – Simon Hayter Jun 17 '16 at 18:32
  • Did that resolve the issue or not? – Simon Hayter Jun 18 '16 at 9:35
1

Found the answer.

On an EC2 instance, ensure the following:

  • Nginx is on, and whatever server_name you're using will allow you to access it.
  • If your server has UFW on, then make sure incoming TCP connections are allowed (on ports 80 and 443)
  • Lastly, go to "edit inbound rules" in your instance's security group, and allow incoming connections via 80 and 443.

Good to go!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.