Skip to content

Instantly share code, notes, and snippets.

@benspaulding
Last active February 8, 2018 04:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benspaulding/56466bfca07c396bed1470407f608892 to your computer and use it in GitHub Desktop.
Save benspaulding/56466bfca07c396bed1470407f608892 to your computer and use it in GitHub Desktop.
Simple start for a Python web app on nanobox.io

Test if Nanobox Python is configured properly

Sometimes getting caught up in the configuration of gunicorn or uWSGI with the configuration of nanobox can be confusing. If you are not getting what you expect, starting here can be a good way to know if you have ports configured properly.

local

When running nanobox run remember that:

  1. You can hit any port on the that development machine.
  2. You must start any processes you want running -- it does not start them for you.
  3. The ports you specify in the web nodes do not have anything to do with nanobox run.

As a convenience the dev machine does forward port 80 to 8080.

> nanobox run
...
--------------------------------------------------------------------------------
+ You are in a Linux container
+ Your local source code has been mounted into the container
+ Changes to your code in either the container or desktop will be mirrored
+ If you run a server, access it at >> 172.20.0.18
--------------------------------------------------------------------------------

/app $ python3 -m http.server --bind 0.0.0.0 8080
Serving HTTP on 0.0.0.0 port 8080 (http://0.0.0.0:8080/) ...
172.20.255.254 - - [07/Feb/2018 16:43:43] "GET / HTTP/1.1" 200 -

In the browser I can visit http://172.20.0.1:8080 (or http://172.20.0.1 since my process is running on port 8080) and be served the index page. But if my process was on some other port, say 8000, I would have to hit that port directly; nanobox dev is not going to forward anything magically.

dry-run

But when running a proper deploy (including dry-run) you must hit the ports mapped by the web components. If you define none it is http:80:8080 and http:443:8080 by default. That is to say that nanobox will send all traffic from 80 and 443 to your web node on 8080. You do not need to handle any SSL -- nanobox handles SSL termination for you.

> nanobox deploy dry-run
...
--------------------------------------------------------------------------------
+ Your app is running in simulated production environment
+ Access your app at >> 172.20.0.19
--------------------------------------------------------------------------------


Connected to streaming logs:
ctrl + c to quit
------------------------------------------------
waiting for output...

Wed Feb 07 16:53:00 2018 web.main (app[daemon]) ::  172.20.0.19 - - "GET / HTTP/1.1" 200 -

In the browser I can now hit my app deployed to dry-run at both http://172.20.0.1 and https://172.20.0.1. But I cannot hit it on port 8080 any more.

Final Notes

  • Don’t run any of your processes on any port < 1024 -- that will require sudo and will likely cause all sorts of issues (as well as opening security risks that just aren’t necessary).
  • In addition to the above, don’t (in fact, you can’t) run anything on ports 80 or 443 because the nanobox load balancer handles those.
run.config:
engine: benspaulding/nanobox-engine-python
engine.config:
runtime: python-3.6
# runtime: python-2.7
web.main:
start: python3 -m http.server --bind 0.0.0.0 8080
# start: python2 -m SimpleHTTPServer 8080
<title>Hello, nanobox!</title>
<h1>Hello, nanobox!</h1>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment