2

I'm trying to configure my nginx reverse proxy using configs I've used as templates for ages. For some reason, I'm now getting the following error:

# nginx -t
nginx: [emerg] no "ssl_certificate" is defined for the "listen ... ssl" directive in /etc/nginx/sites-enabled/movies.domain.com:1
nginx: configuration file /etc/nginx/nginx.conf test failed

Note the oddity here: It's reporting the listen directive is on line 1. The contents of the file are below (note - I've output the entirety of the cat command so that you can see there is no whitespace at the top of the file):

root@spanners:/etc/nginx/sites-enabled# cat movies.domain.com 
server {
    #Open 80 for the 301 Redirect
    listen 80;
    listen [::]:80;

    #This is the name of the server that we want to connect.
    server_name movies.domain.com;

    # The Actual Redirect itself
    return 301 https://movies.domain.com;
}
server {
    # The Actual Listening Port
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name movies.domain.com;
    ssl_certificate           /etc/letsencrypt/live/domain.com/fullchain.pem;
    ssl_certificate_key       /etc/letsencrypt/live/domain.com/privkey.pem;

      location / {

      include /etc/nginx/include.d/proxy_settings.conf;

      proxy_pass    http://192.168.1.237:7878;
    }
}

The full contents of /etc/nginx/include.d/proxy_settings.conf are as follows:

root@spanners:/etc/nginx/sites-enabled# cat ../include.d/proxy_settings.conf 
      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-Proto $scheme;

      proxy_read_timeout  90;

I have seen this question, and this answer, in which both are missing the certificates, and give the correct line in the file.

There doesn't seem to be anything special here, but nginx is still reporting the listen...ssl on line 1. For reference, IPv4 and IPv6 are enabled on this box, and while I realise the proxy pass is not forwarding to a IPv6 address, but that does not cause the same error on the other 11 config files in the same directory.

Am I missing something here?

ScottC
  • 148
  • 1
  • 5
  • 1
    The line number may be misleading as the error can only be generated after the entire `server` block has been parsed. But use `nginx -T` (uppercase `T`) to view the entire configuration across all included files to ensure that the error does not relate to the file included just before `sites-enabled/movies.domain.com`. Also, make sure that the line before `ssl_certificate` is correctly terminated with a `;`. – Richard Smith Jan 06 '21 at 11:55
  • 1
    I just had to log in to say, the previous line not being terminated by a semicolon was EXACTLY my issue. Thank you @RichardSmith! Not sure how useful this was to ScottC but it made my day! – AIGuy110 Apr 15 '21 at 09:17
  • Seconding the missing semicolon solution! Thank you @RichardSmith. – Ryan McGrath May 28 '21 at 20:33

0 Answers0