【发布时间】:2018-04-22 01:22:07
【问题描述】:
我是 AWS 的新手。我创建了一个 aws 帐户(免费套餐)并启动了一个 ec2 实例。 我已经安装了 apache tomcat7 和 mysql 来托管一个 Web 应用程序。 Web 应用程序是用 Java(jsp 页面)创建的。
现在我可以使用 url 访问 Web 应用程序: http://ec2-ipv4address-aws.com:8080/AppName/Login
我的要求如下:
1. My friend have a domain example.com and we have created a subdomain business.example.com.
2. We have redirected http://business.example.com to my web application deployed in tomcat listening to port 8080.
So now we can access the web application using the url:
http://business.example.com:8080/AppName/Login
3. But our requirement is that when a user access http://business.example.com we need to show the Login page.
Is this possible ?
我研究并发现了一些与反向代理相关的东西。 一些链接说我们需要在 apache 配置文件中设置反向代理。 我试过这样做,但没有成功。
尽管我知道将应用程序部署在 tomcat webapps 文件夹中,但我并不是高级配置修改方面的专家。
请大家帮忙。提前致谢。
我将我的配置更改粘贴到 VirtualHost 标签下的 httpd.conf 中:
<VirtualHost *:80>
ServerName business.example.com
ProxyRequests On
<Directory />
AllowOverride None
</Directory>
<Directory /var/lib/tomcat7/webapps/>
AllowOverride All
Require all granted
Options Indexes FollowSymLinks
</Directory>
ProxyPass / http://ipv4address:8080/AppName/Login/
ProxyPassReverse / http://ipv4address:8080/AppName/Login/
<Location "/webapps">
Order deny,allow
Allow from all
</Location>
</VirtualHost>
我的 httpd.conf 文件有以下部分注释:
#
# Allow remote server configuration reports, with the URL of
# http://servername/server-info (requires that mod_info.c be loaded).
# Change the ".example.com" to match your domain to enable.
#
#<Location /server-info>
# SetHandler server-info
# Order deny,allow
# Deny from all
# Allow from .example.com
#</Location>
#
# Proxy Server directives. Uncomment the following lines to
# enable the proxy server:
#
#<IfModule mod_proxy.c>
#ProxyRequests On
#
#<Proxy *>
# Order deny,allow
# Deny from all
# Allow from .example.com
#</Proxy>
我收到一个页面,显示错误 502,网关错误。请检查此网址: https://drive.google.com/open?id=19YT3_LnJuVznvMizPkqD0ppeuA_nSnTp
我尝试将在端口 80 上收到的请求重定向到端口 8080。 要添加 iptables 重定向规则,请以 root 身份 SSH 到服务器并执行以下命令:
# iptables -A INPUT -i eth0 -p tcp --dport 80 -j ACCEPT
# iptables -A INPUT -i eth0 -p tcp --dport 8080 -j ACCEPT
# iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080
然后使用命令保存 iptables:service iptables save
还使用命令重新启动 iptables:service iptables restart
【问题讨论】:
标签: java apache amazon-web-services tomcat reverse-proxy