【问题标题】:Nginx | 2 Domains (1x Node App, 1x Static HTML) on one serverNginx |一台服务器上的 2 个域(1x 节点应用程序,1x 静态 HTML)
【发布时间】:2016-08-11 09:02:37
【问题描述】:

我无法同时在两个单独的域上运行一个节点应用程序和一个静态页面(仅 html)。无论我尝试什么,静态域总是被重定向到节点应用程序(在端口 3000 上)

这里是“站点可用”文件:

节点应用:

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


server_name www.domain1.com domain1.com;

# and redirect to the https host (declared below)
return 301 https://domain1.com$request_uri;
}

server {
    listen 443;
    server_name domain1.com www.domain1.com;

    ssl on;
    # Use certificate and key provided by Let's Encrypt:
    ssl_certificate /etc/letsencrypt/live/domain1.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/domain1.com/privkey.pem;
    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';


    location / {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Host $http_host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-NginX-Proxy true;
            proxy_pass http://localhost:3000/;
            proxy_ssl_session_reuse off;
            proxy_set_header Host $http_host;
            proxy_cache_bypass $http_upgrade;
            proxy_redirect off;
    }
}

还有静态的:

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


   #server_name www.domain2.com domain2.com;

   root /var/www/html/domain2;
   index index.html index.htm;


   return 301 https://domain2.com$request_uri;
}

server {

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

   root /var/www/html/domain2;

   index index.html index.htm;

   ssl_certificate /etc/letsencrypt/live/domain2.com/fullchain.pem;
   ssl_certificate_key /etc/letsencrypt/live/domain2.com/privkey.pem;
}

默认配置文件为空。任何帮助/提示将不胜感激。

在我为 domain2 生成 Let's encrypt 证书之前,它工作正常,将两个域放在单独的配置中并删除默认值。

提前谢谢你!

【问题讨论】:

  • 你是否安装了指向sites-enabled的符号链接?
  • 嗨,理查德,感谢您的评论。是的,符号链接已安装。

标签: html node.js nginx dns host


【解决方案1】:

问题是您的静态域配置中没有server_name 指令。因此,请求总是被您的默认服务器块捕获,这似乎是您的节点应用程序。

查看详情:

【讨论】:

  • VBart,非常感谢!问题解决了!再次感谢!
猜你喜欢
  • 1970-01-01
  • 2021-11-17
  • 1970-01-01
  • 1970-01-01
  • 2019-10-29
  • 2018-02-03
  • 2017-11-03
  • 1970-01-01
  • 2015-10-29
相关资源
最近更新 更多