我在 AWS 中有一个运行多个应用程序服务器的 Ubuntu 服务器——一个 Wildfly 提供一些页面,两个 Tomcat 运行一个单独的应用程序。
我正在尝试让子域正常工作。
我将 DNS 设置为指向 subdomain1.example.com、subdomain2.example.com。那很好用。
Wildfly 正在监听端口 80(我认为?),Tomcat 正在监听 8080 和 8090。目标是让 www.example.com 转到 Wildfly,subdomain1.example.com 转到 Tomcat:8080 和 subdomain2 .example.com 转到 Tomcat:8090
我发现很多帖子都在谈论在 Apache 中设置虚拟主机,应该可以解决我的问题。但我总是被送进兔子洞。一些建议添加到 /opt/bitnami/apache2/bin/httpd.config
一些建议将其添加到 /opt/bitnami/apache2/sites-available/subdomain1.example.com.conf
我的第一个问题:我认为 Apache 甚至没有运行。我的印象是 Apache 被烘焙到 Wildfly 中,但是当我执行时:
service apache2 status
我得到:
apache2.service Loaded: not-found (Reason: No such file or directory) Active: inactive (dead)
运行 sudo service --status-all
也没有显示它正在运行,所以我认为它不是。它似乎安装(Bitnami 堆栈)在 /opt/bitnami/apache2
作为 Wildfly 的一部分,我是否必须打开 Apache(以及如何打开它)?如果我这样做,那么我会假设 Wildfly 不再获得流量。
其次 - 我的研究告诉我我需要使用 a2enmod
和 a2ensite
启用 proxy
和 proxy_http
但我没有这些。研究表明,所有 Ubuntu 都会有这些脚本……如果我打开 Apache,它们会被创建吗?
很抱歉提出所有菜鸟问题……我是一名没有 DevOps 人员的开发人员。这似乎很常见,它会被烘烤,或者会有一个我可能会遗漏的明确解决方案。
最佳答案
对于那些寻找类似东西的人,这里是对我有用的解决方案。
我的服务器是 AWS 上的 Wildfly-Apache2-MySQL AMI 镜像。我不需要像我的研究建议的那样使用 a2enmod 或 a2ensite。预构建镜像似乎已经启用了其中许多模块。
请注意这些说明是 BITNAMI AWI 特定的 - 您的 flavor 配置可能略有不同
要让子域指向一个简单的 Apache 文本站点 (yada.example.com):
- 在 ~/stack/apache2/htdocs 中创建一个名为 yada 的目录
- 在虚拟主机配置文件中添加一个条目(
sudo nano/opt/bitnami/apache2/conf/extra/httpd-vhosts.conf
)
<VirtualHost *:80>
ServerAdmin info@example.com
DocumentRoot "/opt/bitnami/apache2/htdocs/yada"
ServerName yada.example.com
ErrorLog "logs/yada-subdomain-error-log"
CustomLog "logs/yada-subdomain-access-log" common
</VirtualHost>
- 修改 Apache 配置文件以包含虚拟主机。 (
sudo nano/opt/bitnami/apache2/conf/httpd.conf
):
...snip...
# Supplemental configuration
#
# The configuration files in the conf/extra/ directory can be
# included to add extra features or to modify the default configuration of
# the server, or you may simply copy their contents here and change as
# necessary.
...snip...
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
# ADDED THE ABOVE LINE
...snip...
- 重启 Apache(
sudo/opt/bitnami/ctlscript.sh restart apache
)
要使其指向 Tomcat 服务器,请将其添加到 httpd-vhosts.conf
:
<VirtualHost *:80>
ServerAdmin info@example.com
ServerName yada.example.com
ProxyPreserveHost On
# setup the proxy
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyPass / http://localhost:8090/
ProxyPassReverse / http://localhost:8090/
</VirtualHost>
您的端口可能不同。
仅供引用,我发现这很有帮助:https://docs.bitnami.com/virtual-machine/components/apache/#how-to-configure-your-web-application-to-use-a-virtual-host
祝你好运,向@stdunbar 大声疾呼,寻求他的指导。
关于apache - Wildfly、Tomcat、Apache 和子域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49332050/