sudo apt-get install nginx
sudo service nginx start
sudo service nginx stop
sudo service nginx restart
或者
sudo /etc/init.d/ngnix start
sudo /etc/init.d/nginx stop
sudo /etc/init.d/nginx restart
grep /var/log/nginx/error.log
apt-get install python-dev
pip install uwsgi
def application(env, start_response):
start_response('200 OK', [('Contest-Type', 'text/html')] )
return [b'uWSGI is Good!'] #python3
#return ['uWSGI is Good!'] #python2
测试uWSGI,如果显示正确,则说明 web client <-> uWSGI <-> Python 这三个环节是畅通的:
uwsgi --http :8080 --wsgi-file test.py
参数说明:
1. http :8080 : 使用http协议,端口号为8080
2. wsgi-file test.py : 加载指定的文件
uwsgi --http :8080 --module mysite.uwsg
# the upstream component nginx needs to connect to
upstream django {
# server unix:///home/wfc/works/Django/LicenseSite/license.sock; #使用socket文件
server 127.0.0.1:8080; # 使用TCP端口
}
# configuration of the server
server {
# the port your site will be served on
listen 8080;
# the domain name it will serve for
server_name 127.0.0.1; # substitute your machine's IP address or FQDN
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
location /static {
alias /home/wfc/works/Django/LicenseSite/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 /home/wfc/works/Django/LicenseSite/uwsgi_params; # the uwsgi_params file you installed
}
}
sudo ln -s /home/wfc/works/Django/LicenseSite/mysite_nginx.conf /etc/nginx/sites-enabled/
在django项目的setting文件中,添加一行内容:
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
运行collectstatic,主要将admin下静态文件拷贝到项目目录,否则打开的网页没有格式效果:
python manage.py collectstatic
sudo service nginx restart
server unix:///home/wfc/works/Django/LicenseSite/license.sock; #使用socket文件
#server 127.0.0.1:8080; # 使用TCP端口
uwsgi --socket mysite.sock --module mysite.wsgi --chmod-socket=666 # (very permissive)
或者
uwsgi --socket mysite.sock --module mysite.wsgi --chmod-socket=664 # (more sensible)
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = /home/wfc/works/Django/LicenseSite/
# Django's wsgi file
module = LicenseSite.wsgi
# the virtualenv (full path)
home = /home/wfc/works/Django/LicenseSite/venv/
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 10
# the socket (use the full path to be safe
socket = /home/wfc/works/Django/LicenseSite/license.sock
# ... with appropriate permissions - may be needed
chmod-socket = 666
# clear environment on exit
vacuum = true
uwsgi --ini mysite_uwsgi.ini
[Unit]
Description=uWSGI instance
After=network.target
[Service]
User=wfc
WorkingDirectory=/home/wfc/works/Django/LicenseSite
Enviroment=/home/wfc/works/Django/LicenseSite/venv/pyvenv.cfg
ExecStart=/home/wfc/.local/bin/uwsgi --ini /home/wfc/works/Django/LicenseSite/license_uwsgi.ini
[Install]
WantedBy=multi-user.target
sudo systemctl enable mysite
sudo systemctl start epolicense
sudo systemctl restart epolicense
sudo systemctl stop epolicense
sudo systemctl status epolicense