Book Image

NGINX Cookbook

By : Tim Butler
Book Image

NGINX Cookbook

By: Tim Butler

Overview of this book

NGINX Cookbook covers the basics of configuring NGINX as a web server for use with common web frameworks such as WordPress and Ruby on Rails, through to utilization as a reverse proxy. Designed as a go-to reference guide, this book will give you practical answers based on real-world deployments to get you up and running quickly. Recipes have also been provided for multiple SSL configurations, different logging scenarios, practical rewrites, and multiple load balancing scenarios. Advanced topics include covering bandwidth management, Docker container usage, performance tuning, OpenResty, and the NGINX Plus commercial features. By the time you've read this book, you will be able to adapt and use a wide variety of NGINX implementations to solve any problems you have.
Table of Contents (14 chapters)

Easy Flask with NGINX

As one of the more popular Python frameworks, Flask is an extremely lightweight yet powerful system for web applications. Seen as more of a micro framework, a functional Flask application can be as simple as 20 lines of code.

Getting ready

This recipe is based on a very simple, single file Flask application. To show the simplicity, here's the example (demoapp.py) we'll use:

from flask import Flask 
application = Flask(__name__) 
 
@application.route("/") 
def hello(): 
    return "<h1>Demo via Nginx with uWSGI!</h1>" 
 
if __name__ == "__main__": 
    application.run(host='127.0.0.1', port=9001) 

Like the Django recipe, we're going to...