簡體   English   中英

在AWS實例中設置反向代理,運行Tomcat服務器

[英]Setting reverse proxy in aws instance, running tomcat server

我是AWS的新手。 我創建了一個AWS帳戶(免費)並啟動了一個ec2實例。 我已經安裝了Apache tomcat7和mysql來托管Web應用程序。 該Web應用程序是用Java(jsp頁面)創建的。

現在,我可以使用以下網址訪問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 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM