After [previous article] (http://www.the5fire.com/python-supervisor-django-demo.html) talked about using supervisor to manage the process, it is natural to talk about using nginx to manage the ports monitored by the former startup program.
The first is to install nginx, the environment is still ubuntu12.04 (64-bit), through the following command:
sudo apt-get install nginx
After the installation is complete, it is started. At present, I know there are two ways to start under ubuntu:
sudo /etc/init.d/nginx start #Through init.The startup file under d starts.
sudo service nginx start #Start via ubuntu's service manager
Enter http://localhost in the browser and see if the "Welcome to nginx!" page appears. If not, continue to read the configuration first.
The last article talked about using supervisor to start two django processes, listening on ports 8000 and 8001 respectively, then how to make nginx forward access to these two ports, this must be done through the configuration file.
In my system, the nginx configuration file is under /etc/nginx.
Open the nginx.conf file and configure as follows:
# user www-data;
worker_processes 4;
pid /var/run/nginx.pid;
events {
use epoll;
worker_connections 768;
# multi_accept on;}
http {
include mime.types;
default_type application/octet-stream;
keepalive_timeout 120;
tcp_nodelay on;
upstream localhost {
server 127.0.0.1:8000;
server 127.0.0.1:8001;}
server {
listen 80;
server_name localhost;
location /{
proxy_pass http://localhost;
proxy_set_header Host $host;
proxy_set_header X-Real_IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}}}
This is ok, restart your nginx: sudo service nginx restart.
Then you can directly visit http://127.0.0.1 to access the django program that you started with supervisor, and load it on two ports. If you are interested, you can refer to my previous article "The Use of Web Stress Test ab Test" for down-stress test to see if it works.
Recommended Posts