AI Robots
AI Robots

Reputation: 21

Nginx SSL connection refused, but works locally

I have a problem with Nginx SSL setting. I have a default setting of /etc/nginx/nginx.conf

I tried with a very simple setting in /etc/nginx/sites-enabled:

server
{
    listen                 80;
    server_name            sub.mydomain.com;
    return                 301 https://$host$request_uri;
    # This root works
    #root                   /var/www/html;
}

server
{
    listen                 443 default_server ssl;
    server_name            sub.mydomain.com;
    ssl                    on;
    ssl_certificate        /var/www/html/cert.pem;
    ssl_certificate_key    /var/www/html/key.pem;
    root                   /var/www/html;
}

HTTP works, but not HTTPS. I get connection refused when running:

curl -v https://sub.mydomain.com

I have tried setting /etc/hosts to:

127.0.0.1    sub.mydomain.com

There is no problem and I can see the green SSL bar if I access the page using the web browser in the server locally. But, I still get connection refused if I access the page externally using a different computer.

I have also tried enabling the Ubuntu firewall and allowing SSL via:

ufw allow 443

It does not work.

There is no error in the log file of the Nginx

Edit 1

I have tried listen 0.0.0.0:80 and listen 0.0.0.0:443 and still does not work

The output of the netstat -nlp | grep nginx:

tcp    0    0 0.0.0.0:80     0.0.0.0:*    LISTEN    12591/nginx -g daem
tcp    0    0 0.0.0.0:443    0.0.0.0:*    LISTEN    12591/nginx -g daem

Can anyone help please? Thanks.

Upvotes: 1

Views: 2845

Answers (1)

AI Robots
AI Robots

Reputation: 21

I have solved the problem by opening the port 433 in the router. I forget to open the port when I change the router.

Thanks Will for giving the idea about the external firewall.

Upvotes: 1

Related Questions