1

I'm very new to nginx, trying to add SSL on my website with the magnificent letsencrypt, helped with this tutorial

I have my file: /etc/nginx/sites-available/staging.example.com.conf, which contains:

server {
  listen 443 ssl;
  server_name           staging.example.com;

  ssl_certificate /etc/letsencrypt/live/staging.example.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/staging.example.com/privkey.pem;


  access_log            /var/log/nginx/staging.example.com.access.log;
  error_log             /var/log/nginx/staging.example.com.error.log;


  location ~ \.(css|js|gif|jpg|png|html|svg|gz|ttf|otf|eot|woff|ico)$ {
    root                /vagrant/www/current/public;
    expires             10d;
    gzip_static         on;
    gzip_vary           on;
  }

  error_page 502        /502.html;
}

server {
  listen 80;
  server_name staging.example.com;
  return 301 https://$host$request_uri;
}

In /vagrant/www/current/public, I have test.html.

If I cURL http://staging.example.com/test.html, I get:

<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.9.3</center>
</body>
</html>

But if I cURL https://staging.example.com/test.html I get curl: (7) Failed to connect to staging.mojjo.fr port 443: Connection timed out

Can't find any log or something (/var/log/nginx/staging.example.com.error.log doesn't contain anything). Any idea where I could find relevant information?

It feels like the port 80 rule works, but the listen 443 ssl won't.

Using nginx version: nginx/1.9.3

Can someone help? Thanks

0

1 Answer 1

4

Probably your port 443 isn't open (might be blocked by firewall). Check listening ports e.g. with netstat:

netstat -tln

it should include lines like this:

  tcp        0      0 0.0.0.0:80             0.0.0.0:*               LISTEN 
  tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN 

Then check your firewall settings.

You can use single server definition for both HTTP and HTTPS:

server {
      listen 80;
      listen 443 ssl;

...
      if ($scheme = http) {
       rewrite ^ https://$server_name$request_uri? permanent;
      }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.