在 aws 实例中设置反向代理,运行 tomcat 服务器

Setting reverse proxy in aws instance, running tomcat server

我是 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 文件夹上部署应用程序,但我并不擅长高级配置修改。

任何人都请帮忙。提前致谢。

我正在将我的配置更改粘贴到 httpd.conf 的 VirtualHost 标签下:

<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,错误的网关。请检查此 url: 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

你走对了,让我们先试试下面的方法:

<VirtualHost *:80>
ServerName business.example.com

ProxyRequests On
ProxyPreserveHost On

ProxyPass / http://127.0.0.1:8080/AppName/
ProxyPassReverse / http://127.0.0.1:8080/AppName/

</VirtualHost>

应用后,您应该可以打开http://business.example.com/Login