【问题标题】:How to prevent a port number to other sub domains using Nginx v1.14.1?如何使用 Nginx v1.14.1 防止端口号到其他子域?
【发布时间】:2019-04-01 11:08:42
【问题描述】:

有两个子域app.example.com和admin.example.com,使用nginx v 1.14.1,表达js。

错误:

  1. 端口在两个子域中运行,例如:8080 在 app.example.com 和 admin.example.com 中运行我该如何防止这种情况发生?
  2. 进入带有端口号 8080 和 8081 的子域后,它不会重定向到 80。否则我应该阻止从 URL 输入此端口号。

virtual.conf

server {
      listen admin.example.com:80;
      server_name admin.example.com;
      location / {
        proxy_pass http://127.0.0.1:8080;
      }
}

server {
      listen app.example.com:80;
      server_name app.example.com;
      location / {
        proxy_pass http://127.0.0.1:8081;
      }
}

【问题讨论】:

  • 防火墙,或在您的节点项目内app.listen(8080, '127.0.0.1')
  • @RolandStarke - 我已经完成了,现在显示 Nginx 欢迎页面,告诉我们编辑 /etc/nginx/nginx.conf,下一步是什么?
  • app.example.comadmin.example.com 显示此欢迎屏幕
  • 在更改 app.listen 之前它有效吗?斯里帮不上忙。 (我会选择listen 80;
  • @RolandStarke - 我们解决了错误。 :)

标签: node.js express nginx


【解决方案1】:

已解决:

  • 将 server.js 行 app.listen('8080') 更改为 app.listen('8080', '127.0.0.1')
  • 重新启动 nginx,然后得到我所有子域和私有 IP 的 nginx 欢迎页面。
  • 从 virtual.conf 中删除了listen 行的子域名。
  • 再次重新关注nginx

virtual.conf

server {
      listen 80;
      server_name admin.example.com;
      location / {
        proxy_pass http://127.0.0.1:8080;
      }
}

server {
      listen 80;
      server_name app.example.com;
      location / {
        proxy_pass http://127.0.0.1:8081;
      }
}

【讨论】:

    猜你喜欢
    • 2014-06-19
    • 1970-01-01
    • 1970-01-01
    • 2020-09-03
    • 2017-04-01
    • 2018-02-22
    • 1970-01-01
    • 2014-07-02
    • 2014-01-13
    相关资源
    最近更新 更多