Neo
Neo

Reputation: 1269

server program exits when i close SSH connection to GCP

I have an Ubuntu instance on Google Cloud Platform (GCP). I want to use it as an HTTP server to access files. I simply use this python command, type it in bash:

python3 -m http.server 8000

This will run http.server module as a script, construct a simple HTTP server and listen at port 8000.

Problem is that, since I use GCP instance, I must connect to it remotely (for example I use SSH shell provided by GCP). When I close the SSH shell, the python HTTP server will stop. So what should I do to make sure that the server still runs after I close the shell?

I did searched on Google, and I tried to use

nohup python3 -m http.server 8000 &

This command, I quote, will run the instruction as a background program and persist running after exiting bash. But it seems that this doesn't work for my situation.

Anybody can help?

Upvotes: 1

Views: 603

Answers (2)

Shreck Ye
Shreck Ye

Reputation: 1869

Try the screen command. I think it's easier to use and also more flexible than nohup as you can also reattach processes after detaching then. See this answer for details.

Upvotes: 1

Dustin Ingram
Dustin Ingram

Reputation: 21580

The http.server module is not meant to be a full-fledged webserver.

You'll want to set up something like Apache instead, see Running a basic Apache web server.

Upvotes: 1

Related Questions