0

I'm getting an error in my Nginx config file.

Running systemctl status nginx.service I get:

Mar 08 19:32:26 ansible-test nginx[1118]: nginx: [emerg] invalid host in "[::]443" of the "listen" directive in /etc/nginx/sites-enabled/www.mywebsite.org.conf:78
Mar 08 19:32:26 ansible-test nginx[1118]: nginx: configuration file /etc/nginx/nginx.conf test failed
Mar 08 19:32:26 ansible-test systemd[1]: nginx.service: Control process exited, code=exited status=1

Here's my config file:

add_header Content-Security-Policy "default-src 'self'  ... ;

add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;

add_header X-Content-Type-Options nosniff;

add_header X-Frame-Options SAMEORIGIN;

add_header X-XSS-Protection "1; mode=block";

server_tokens off;

server {
  listen [::]:80;
  listen 80;
    server_name subdomain.mywebsite.org;
  return 301 https://$server_name$request_uri;
}


server {
  listen [::]:80;
  listen 80;
    server_name www.mywebsite.org;
  return 301 https://$server_name$request_uri;
}

server {
  listen [::]:80;
  listen 80;
    server_name mywebsite.org;
  return 301 https://www.mywebsite.org/$request_uri;
}

proxy_cache_path /var/www/mywebsite/cache levels=1:2 keys_zone=mywebsite_cache:10m max_size=10g
                 inactive=60m use_temp_path=off;

server {
         listen [::]443 ssl http2 default_server;
         listen 443 ssl http2 default_server;

            ssl on;
      ssl_certificate /etc/nginx/ssl/myCA.pem;
      ssl_certificate_key /etc/nginx/ssl/myCA.key;

    location /blah.html { alias /var/www/mywebsite/static_assets/blah.html; }
    location /robots.txt { alias /var/www/mywebsite/static_assets/robots.txt; }
    location /img { alias /var/www/mywebsite/static_assets/img; }
    location /files { alias /var/www/mywebsite/static_assets/files; }

    location / {
        proxy_cache mywebsite_cache;
        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;
    }
}

I'm using Nginx as a reverse proxy to a NodeJS server (running a Meteor app).

Where did I go wrong?

  • "listen [::]443 ssl http2 default_server;" is the problem. Take it out and check things generally work. Then add the line back in one part at a time to see what's causing the problem. Use a process of elimination. Once you work it out please answer your own question. – Tim Mar 9 '18 at 3:34
1

You have listen [::]443 when you should have listen [::]:443.

  • So small I didn't notice. Thanks. – OrdinaryHuman Mar 9 '18 at 12:57

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.