简体   繁体   English

Nginx 中的服务器块被忽略

[英]Serverblock being ignored in Nginx

so I am trying to host multiple websites on a single server with nginx.所以我正在尝试使用 nginx 在单个服务器上托管多个网站。 I have a config set up, and the DNS records all work, and some of the things work, but one of the domains doesn't.我设置了一个配置,DNS 记录了所有工作,其中一些工作正常,但其中一个域没有。

server {
        listen 80 ;
        listen [::]:80 ;


        root /var/www/aphrim.dev/html;

        index index.html index.htm index.nginx-debian.html;
    server_name aphrim.dev www.aphrim.dev; # managed by Certbot


        location / {
                try_files $uri $uri/ =404;
        }


    #listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/aphrim.dev/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/aphrim.dev/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot



}
server {
        listen 80 ;
        listen [::]:80 ;


        #root /var/projects/aphrim.dev/html;

        index index.html index.htm index.nginx-debian.html;
    server_name projects.aphrim.dev; # managed by Certbot


        location / {
                proxy_pass http://127.0.0.1:3002;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
        }


    listen [::]:443 ssl; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/projects.aphrim.dev/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/projects.aphrim.dev/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

server {
    listen 80; 
    listen [::]:80;

 #   root /var/projects/aphrim.dev/html;
    index index.html index.htm index.nginx-debian.html;

    server_name techchan.org;

    location / {
        proxy_pass http://127.0.0.1:3002;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
    }
}

So, I am trying to get the 3rd server block to work, instead it just displays the content of the 1st server block.所以,我试图让第三个服务器块工作,而不是只显示第一个服务器块的内容。 I know the content of the 3rd server block works because I put it onto the 2nd server block and it works.我知道第三个服务器块的内容有效,因为我将它放在第二个服务器块上并且它有效。 If anyone has a solution I would be very grateful.如果有人有解决方案,我将不胜感激。

After a few hours of searching, found the issue.经过几个小时的搜索,找到了问题所在。 If anyone ever has the same question, just add如果有人有同样的问题,只需添加

listen [::]:443 ssl;
listen 443 ssl;

and it should be fixed, at least that is what fixed it for me.它应该是固定的,至少这对我来说是固定的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM