Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Starting http-server on Amazon EC2

I'm trying to setup and access a simple Python http-server on an Amazon EC2 instance. The server works locally under localhost:80, but I cannot get it to work on the EC2 instance.

I connected an elastic IP to the instance, and it at least works to access ssh on that IP.

I think the problem is that I'm setting the server_address for the HTTPServer incorrectly: Python HTTPServer documentation Since I really don't have a clue, at home I configured the router to forward HTTP requests to the computer's local IP, 192.168.1.xx

I thought that it might be a security group issue, so I added inbound HTTP with source 0.0.0.0/0 (which I thought should allow all incoming IPs) and sets port 80 without any option to change.

Additionally, I think that running the server script under sudo on port 80 is a potential security risk. Is there any way to forward the request under another port like 8080 instead of 80?

like image 797
SlimJim Avatar asked Feb 27 '13 22:02

SlimJim


2 Answers

For the security group, you can create a rule that allows port 8080 (Do "Custome TCP Rule", then put 8080 for the port range).

It sounds likely that your HTTPServer is binding to loopback. I would set the address to 0.0.0.0 (all interfaces), set the port to 8080, and open 8080 on your security group.

like image 190
Alex Avatar answered Oct 22 '22 10:10

Alex


From a security point of view it might be better to run your script behind a regular http server.

Here is a configuration for NginX that should get you started (puth this file in /etc/nginx/conf.d/):

upstream myscript  {
  server localhost:8080;
}

server {
    server_name _;
    listen 80;
    location = / {
        proxy_pass  http://myscript;
    }
}

In this setting, you run your script on port 8080 (use server_address = ('localhost', 8080) to configure your HTTPServer in your python script).

So when a query hits nginx on port 80 it forwards it to localhost port 8080 where your script takes in charge.

like image 39
oDDsKooL Avatar answered Oct 22 '22 09:10

oDDsKooL