Setting Up AWS Firewall
First thing to do here is opening up the port 80 for your EC2 instance in AWS cloud.Click on the the Security Groups of your instance. Mine its launch-wizard-1.
In next page, click on the Inbound tab and click Edit in the bottom of the page
Clicking on Edit will get you here. We have to add a a new rule here by clicking on Add Rule button below. We are able to ssh to the cloud since the SSH port 22 is opened for us by default.
Once you click the Add Rule button, select HTTP as the Type. Every other thing will be automatically filled.
Click on Save. That's it. We have opened up the 80 port !!! But wait, the job is halfly done. We have to do some other stuff also ...
Setting up Apache2 and Tomcat
Install Apache2 and Apache Tomcat 7 to your cloud. For Ubuntu ;- Apache 2 :
- sudo apt-get install apache2
- Apache Tomcat 7 :
- wget http://apache.mirrors.hoobly.com/tomcat/tomcat-7/v7.0.55/bin/apache-tomcat-7.0.55.tar.gz ( you can wget from any download location, it's fine :) )
We are going to put up apache2 to listen to the requests that comes to port 80 . And then we will redirect those to tomcat accordingly. Apache2 will be listening to the port 80 and Tomcat will be listening to the port 8080 by default.
Add the ProxyPass to redirect the request to tomcat
Things here are as follows
/get-all-users is the url or the path that apache2 will receive. Say your domain name is test-aws-services.com. Then, if you invoke the request as this, " http://test-aws-services.com/get-all-users ".Then the above ProxyPass will work and it will pass that request to http://localhost:8080/my-app/get-all-users-listener
get-all-users-listener is a servlet that I have configured in my web application.
If you want to redirect all the requests that apache receives, you can omit the path. Simply add / to the path.
Ex :
Apache2 Configurations
Enable proxy and proxy_http first with following.
a2enmod proxy
a2enmod proxy_http
Open the file /etc/apache2/apache2.conf. This is the new place for apache2 configurations instead of httpd.confAdd the ProxyPass to redirect the request to tomcat
ProxyPass /the_calling_url http://the_redirected_url
Ex :
ProxyPass /get-all-users http://localhost:8080/my-app/get-all-users-listener
Things here are as follows
get-all-users-listener is a servlet that I have configured in my web application.
If you want to redirect all the requests that apache receives, you can omit the path. Simply add / to the path.
ProxyPass / http://localhost:8080/my-app/get-all-users-listener
Same as this, we can add reverse proxy also. This will send everything out from Tomcat to port 80.
ProxyPassReverse / http://localhost:8080/
Tomcat Configuration
In Tomcat, open the <CATALINA_HOME>/conf/server.xml file and modify the following block as follows. Add proxyPort="80". This is used for Reverse Proxy. This tells Tomcat to send all the responses to the Port 80.
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
proxyPort="80"
/>
So, that's it folks. This is how I got it work. There might be some variations or dependencies with your deployment on AWS. Hope this helps. Cheers !!!!
Great article aiya :)
ReplyDeleteThanks a lot Malli (y)
Delete