AWS implementation often happens

So, I have a very simple deployment on an EC2 instance, which works mostly, except for a few big problems. Right now I just go into the box and run

python -m SimpleHTTPServer 80 

and I have a field in the security group that allows HTTP requests in port 80.

This seems to work, but if I leave it alone for a while (usually 1-2 hours), my elastic ip will start returning 404s. I really need this server in order not to participate in demonstrations to third parties. Any ideas on how to make sure it stays?

In addition, it closes when I close the terminal, which is ssh'd in my field, which is extremely not ideal, since I would like this demo to not sleep, even if my computer is turned off. This is a less urgent matter, but any advice on this will also be appreciated.

+4
source share
3 answers

SimpleHTTPServer simply serves static pages on port 80, mainly for use during development.

For production use (if you want to use EC2), I recommend that you read Apache or nginx . Basically you need a web server that runs on Linux.

If you think your site will remain static (HTML, CSS, JS), I recommend that you host them on Amazon S3. S3 is cheaper and more reliable. Take a look at this answer for instructions: Amazon S3 Static Hosting - DNS Configuration

Enjoy it!

0
source

Use screen ! Here is a quick tutorial: http://www.nixtutor.com/linux/introduction-to-gnu-screen/

Essentially, just ssh in, open a new window through the screen, start the server via python -m SimpleHTTPServer 80 , then disconnect it from the window. In addition, you should be able to close the terminal, and it should remain in place.

+3
source

I managed to crack a little bit by building a cron job to run the bash script that the server deployed, but I'm not sure if this is the best way. I seem to have solved my problems in the short term. For reference, this is the code I used:

 import SimpleHTTPServer import SocketServer PORT = 80 Handler = SimpleHTTPServer.SimpleHTTPRequestHandler httpd = SocketServer.TCPServer(("", PORT), Handler) httpd.serve_forever() 

Which I concluded in a simple bash script:

 #!/bin/bash cd relevant/directory sudo -u ubuntu python simple_server.py 

I'm sure it was better to allow use, but after that I just ran

 chmod -R 777 bash_script.sh 

So that there are no problems with this front.

And then placed in a cronjob to run every minute (the more the merrier, right?)

 crontab -e (Just to bring up the relevant file) 

Added to this line:

 */1 * * * * path/to/bash_script.sh 

And it seems to work. I closed my ssh'd terminal and everything still works and there was nothing left. I will update if something does, but I'm generally happy with this decision (not that I will be in 2 weeks when I learn more about the subject), but it seems very minimal and low, which means that I at least I understand what I just did.

+1
source

Source: https://habr.com/ru/post/1492531/


All Articles