【问题标题】:Setting reverse proxy in aws instance, running tomcat server在aws实例中设置反向代理,运行tomcat服务器
【发布时间】: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


    【解决方案1】:

    你是在正确的轨道上,让我们先尝试以下:

    <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

    【讨论】:

    • 非常感谢。很高兴听到我在正确的轨道上。我已经替换了“httpd.conf”文件中的条目。但它没有用。我是否需要等待一段时间才能反映这些变化。我已经使用命令“service httpd restart”重新启动了 apache。
    • 重启apache就够了。 究竟在浏览器中发生了什么,你有什么错误吗?
    • 在浏览器中,我收到错误 502,网关错误。
    • 您能否检查一下apache错误日志(通常在/var/log/httpd/文件夹中)是否有与您的请求相对应的条目
    • error_log 文件中没有显示此错误。这是最后几条日志:[Thu Nov 09 09:41:28 2017] [notice] Digest:为摘要身份验证生成秘密 ... [Thu Nov 09 09:41:28 2017] [notice] Digest:完成 [Thu Nov 09 09:41:29 2017] [notice] Apache/2.2.34 (Unix) DAV/2 已配置 -- 恢复正常操作
    猜你喜欢
    • 2021-11-27
    • 1970-01-01
    • 2022-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-04
    • 1970-01-01
    • 2017-04-01
    相关资源
    最近更新 更多