Most guides show how to set up servers on a Linux box (which makes sense) but macOS also works if you don't have a Linux box handy.
This article is just the README.md
to the repo where everything is implemented, so go there if you'd like to follow along. I've also posted this on Stack Overflow in very condensed form.
+---------------+
| Nginx |
| |
| |
+---------------+
X
X
X
X
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
X X
X X
X X
+----------------+ X
| gunicorn | X
| | X
| | +----------------+
+----------------+ | static |
X | assets |
X | |
+----------------+ +----------------+
| Flask |
| |
| |
+----------------+
nginx
and httpie
make help
) +---------------+
| Nginx |
| |
| |
+---------------+
X
X
X
X
XXXXXXXXXXXXXXX
X
X
X
X
X
X
+----------------+
| static |
| assets |
| |
+----------------+
brew install nginx
make ng-serve
make ng-hit
to hit our Nginx server, which will return its default welcome page$ make ng-hit
http http://127.0.0.1:8080
HTTP/1.1 200 OK
# other output
<h1>Welcome to nginx!</h1>
/etc/nginx/nginx.conf
) to point at our repo's static assets- location / {
+ location /static {
- root html;
+ root path/to/your/nginx-wsgi;
- index index.html index.htm;
+ index my-asset.html;
}
make ng-up
static
route to validate it's serving our bespoke HTML 😄: make ng-static
$ make ng-static
http http://127.0.0.1:8080/static/
HTTP/1.1 200 OK
# other output
<h1>Nginx is serving my-asset.html!</h1>
+----------------+
| gunicorn |
| |
| |
+----------------+
X
X
+----------------+
| Flask |
| |
| |
+----------------+
make pipin
make flask-serve
make flask-hit
$ make flask-hit
http http://127.0.0.1:5000
<h1>Flask running!</h1>
make guni-serve
make guni-hit
$ make guni-hit
http http://127.0.0.1:8000
<h1>Flask running!</h1>
+---------------+
| Nginx |
| |
| |
+---------------+
X
X
X
X
XXXXXXXXXXXXXXXXX
X
X
X
+----------------+
| gunicorn |
| |
| |
+----------------+
+ location / {
+ proxy_pass http://127.0.0.1:8000;
+ }
make ng-up
make ng-hit
-> this time, instead of the default Nginx page, we'll see that the request passes from Nginx to gunicorn and finally to Flask$ make ng-hit
http http://127.0.0.1:8080
HTTP/1.1 200 OK
# other output
<h1>Flask running!</h1>
Now, everything is wired together:
+---------------+
| Nginx |
| |
| |
+---------------+
X
X
X
X
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
X X
X X
X X
+----------------+ X
| gunicorn | X
| | X
| | +----------------+
+----------------+ | static |
X | assets |
X | |
+----------------+ +----------------+
| Flask |
| |
| |
+----------------+
This guide is just to get you up-and-running. For more explanation, here are some articles that helped me from three guys named Cheng, Honza, and Patrick