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

时间:2017-11-09 06:27:22

标签: java apache amazon-web-services tomcat reverse-proxy

我是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,Bad Gateway的页面。请检查此网址: 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

1 个答案:

答案 0 :(得分:0)

你走在正确的轨道上,让我们首先尝试以下方法:

.map(response => new Order(response.json()))

应用此功能后,您应该能够打开http://business.example.com/Login

相关问题