Monday 17 September 2012

Amazon EC2 Basics (Part 2)

The next step would be to associate an elastic IP with your EC2 instance and setup an Apache server:
  1. From your Amazon console, click elastic IPs and Allocate a new address.
  2. Associate it to your EC2 instance (if you don't associate with an instance, you'll be charged).
  3. Wherever you registered your domain name (Godaddy, Namecheap, etc), you're going to have to change the Address Record (A record) to point to your IP. e.g., for Namecheap, click "Manage domains", the "All host records", and enter your EC2 IP address for both the fields as shown below:


  4. You should be able to head over to your registered address (e.g., foo.com) on port 8080 now and see the tomcat manager.
  5. You might want to install Apache 2 (if you want, otherwise, you can just let Tomcat work as a web server instead of a servlet container; using Apache 2 as the server with Tomcat as the container would allow you to fiddle around with modules). In this example, we're going to be using mod_proxy to proxy requests to Tomcat. Apache listens on port 80 and Tomcat on port 8080.
  6. Installing and starting apache is simple:
    • ssh into your instance
    • type sudo yum -y install httpd
    • type sudo /sbin/chkconfig httpd on
    • type sudo /sbin/service httpd start
    • /var/www/html/ is the root web directory; httpd.conf is located at /etc/httpd/conf; mod_proxy is located at /etc/httpd/modules
    • note that after changing httpd.conf, you should restart apache using sudo /sbin/service httpd restart
  7. Before doing anything else, you need to modify your Amazon security group to open up port 80:
    • on your Amazon console, click Security Groups
    • check the box of your security group, click "Inbound", create a custom TCP rule for port 80 (port range would be 80) and add this rule
  8. Also, you might want to modify port 8080 to only accept requests from your instance for added security:
    • on your Amazon console, click Security Groups
    • check the box of your security group, click "Inbound", create a custom TCP rule for port 8080 (port range would be 8080) and under "Source", add your elastic IP e.g., some.ip.foo.bar/32
    • if you were following Part 1 of this series, you should remove the old rule for port 8080, where the "Source" was 0.0.0.0/0
  9. Next, modify your httpd.conf file for any context path that you wish to forward to Tomcat. In this example, I'm forwarding / to http://foo.com:8080/myapp. Note that by default, mod_proxy is already configured properly in this file (otherwise, follow this link, modifying as appropriate):
    • ProxyPass         /  http://foo.com:8080/myapp
      ProxyPassReverse  /  http://foo.com:8080/myapp
  10. Also modify the Tomcat server.xml file:
    • vim /etc/tomcat7/server.xml
    • Make sure that you comment out existing lines which deal with port 8080 and instead add the following line:
    • <Connector port="8080" proxyName="www.foo.com" proxyPort="80"/>
  11. Restart your Tomcat and Apache, and you should be all set. Just type foo.com and you should be able to view your website.

18 comments:

  1. BUY SPOTIFY PLAYS REAL PLAYS TO BOOST YOUR MUSIC.
    We will promote your tracks and give you very good promotion Buy spotify plays

    ReplyDelete
  2. xanax bar mg This dosage provides relief of anxiety for up to 6 hours after it has been ingested, which can help you focus on what needs to be done without being disrupted.

    ReplyDelete
  3. Facts about addiction Addiction stands as the top public health problem in America outstanding all other major diseases including stroke, heart diseases and even cancer. The population of addicts is far larger than the patients suffering from the three mentioned diseases in America with sufferers ranging in millions.

    ReplyDelete
  4. British blue cat Kittens for sale near me English shorthiarWe have been branded as the best cattery for breeding healthy kittens and puppies ready for a home.

    ReplyDelete
  5. canim sohbet Android Dear ChatCanım chat is growing day by day with the android chat service it has given to you and serves you, dear chat lovers, free of charge. You can connect and chat online at any time of the day with your smart devices on our chat site. Anonymous chat is a free chat site that allows you to chat randomly and does not charge any fee or money from our valued chat users.

    ReplyDelete
  6. Sabyasachi - Buy sabyasachi online , Sabyasachi Sarees, Sharara Set & more online at panache haute couture. Shop from the latest Sabyasachi collection online now and give a dreamy start to your second inning of life. You will receive on-time delivery at your doorstep.

    ReplyDelete
  7. How did things change so dramatically, even as California debates collecting sales tax from medical marijuana dispensaries and growing cooperatives? marijuana dispensary

    ReplyDelete
  8. Do you want office Space for rent in Dubai? Get Affordable Dubai Business Center With Spiderbc.

    ReplyDelete
  9. Thank you for your valuable and useful information through the blog.
    Furthermore, I would like to inform you about the Nuform - Best digital marketing company in Noida
    If you like to grow your business online and enhance it to Next Level just visit our website and you will get complete Assistance .
    social media marketing company in noida
    Best seo company in noida

    ReplyDelete
  10. Great content.....keep it
    Om International provides the service of packers and movers in Gurgaon
    https://www.ominternationalpackers.com/

    ReplyDelete
  11. Dinstar UC2000-VF is a Dinstar 16 Port GSM Gateway in a compact field-proven hardware design, used to smoothly transit between mobile and VoIP networks, for transmission of both voice and SMS.

    ReplyDelete