【问题标题】:how to make a proxy for both nodejs apps and apache tomcat apps with nginx by different domain name?如何使用不同域名的 nginx 为 nodejs 应用程序和 apache tomcat 应用程序制作代理?
【发布时间】:2016-12-10 13:01:08
【问题描述】:

我有一个域名,例如 abc.com 和阿里云中只有一个虚拟机,公共 ip 为 112.70.230.217 ,但同时我想运行个人博客“ghost”(nodejs的一个博客项目)和一个在tomcat上的java web应用程序。所以我为我的博客创建了“blog.abc.com”,为 tomcat 应用程序创建了“app.abc.com”,为我的 tomcat 应用程序需要的静态资源创建了“res.abc.com”。

  1. 我将 app.war 移动为 $CATALINA_HOME/webapps/ROOT.war 并使用默认设置(8080 端口)制作 tomcat 并启动 tomcat。

  2. 静态资源在 /data/resource/*

  3. 对于“ghost”应用,它的默认访问地址是localhost:2368。

我的问题是:如何设置nginx服务器配置这三个域地址链接到这三个(#1,#2,#3)

我尝试了以下设置,但所有三个域地址都链接到 #1

【问题讨论】:

  • ghost.conf: 服务器 { 听 80; server_name blog.abc.com;位置 / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header 主机 $http_host; proxy_pass 127.0.0.1:2368; } }
  • app.conf: 服务器 { 听 80; server_name app.abc.com;位置 / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header 主机 $http_host; proxy_pass 127.0.0.1:8080; } } 服务器 { 听 80; server_name 资源.abc.com;位置/资源/{根/数据/资源/;自动索引开启; autoindex_exact_size 关闭; autoindex_localtime 开启; } }
  • 这两个文件都已包含在 nginx.conf 中,我可以确认没有包含额外的服务器块设置
  • 所有域都设置为我提到的某个IP地址(例如112.70.230.217)。

标签: node.js tomcat nginx


【解决方案1】:

使用脚本“include /etc/nginx/sites-enabled/*;”时看起来像这样在 nginx.conf 中,/etc/nginx/sites-enabled/ 中的新配置文件将覆盖配置块。

以这个为例,我在 /etc/nginx/sites-enabled/ 中有两个文件 a.conf 和 b.conf,首先 nginx 将在 a.conf 中加载服务器块,然后在加载 b.conf 时。当 nginx 发现有一个块定义时,它会覆盖之前的一个。我不知道它是否正确,但是当我将 conf 放在一个文件中时,它会以某种方式工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-27
    • 1970-01-01
    • 2018-11-13
    • 1970-01-01
    • 1970-01-01
    • 2019-09-03
    • 2011-11-16
    • 1970-01-01
    相关资源
    最近更新 更多