zhaoyatao.com
django + uwsgi + nginx, deploy note.html
# README
# Setting up Django and your web server with uWSGI and nginx
https://uwsgi.readthedocs.io/en/latest/tutorials/Django_and_nginx.html
# prepare job
pip install Django
django-admin.py startproject mysite
cd mysite
pip install uwsgi
sudo apt-get install nginx
# start nginx
sudo /etc/init.d/nginx start
// kill port
lsof -i:8000
kill -9 PID
// kill ps
kill -9 PID
# vim setting.py add this
import os
ALLOWED_HOSTS = ["*"]
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
# run django's "hello, new world". easy way
python3 manage.py runserver 0.0.0.0:8002
# make sure, it will done
# press Ctrl + C, to quit and stop the ps
uwsgi --http :8002 --module mysite.wsgi
# open a Brower: 166.12.21.140:8002
# done :-)
# Ctrl + C
// hard way
# CONFIGURE NGINX FOR YOUR SITE
# You will need the uwsgi_params file, which is available in the nginx directory of the uWSGI distribution, or from https://github.com/nginx/nginx/blob/master/conf/uwsgi_params
# Copy it into your project directory. In a moment we will tell nginx to refer to it.
# Now create a file called mysite_nginx.conf in the /etc/nginx/sites-available/ directory, and put this in it:
# Copy it into your project directory
cd /etc/nginx
ls
cp uwsgi_params ~/mysite/uwsgi_params
# create a file
vim mysite_nginx.conf
# mysite_nginx.conf
# the upstream component nginx needs to connect to
upstream django {
# server unix:///path/to/your/mysite/mysite.sock; # for a file socket
server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}
# configuration of the server
server {
# the port your site will be served on
listen 8000;
# the domain name it will serve for
server_name 166.12.21.140; # substitute your machine's IP address or FQDN
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias /mysite/media; # your Django project's media files - amend as required
}
location /static {
alias /mysite/static; # your Django project's static files - amend as required
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include uwsgi_params; # the uwsgi_params file you installed
}
}
uwsgi --socket :8001 --module mysite.wsgi
# open 8000 port
open a Brower: 166.12.21.140:8000
done