Nginx 无效主机错误

Nginx 无效主机错误

我的 Nginx 配置文件中出现错误。

运行systemctl status nginx.service我得到:

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

这是我的配置文件:

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;
    }
}

我正在使用 Nginx 作为 NodeJS 服务器(运行 Meteor 应用程序)的反向代理。

我哪里做错了?

答案1

listen [::]443当你应该拥有的时候你就拥有了listen [::]:443

相关内容