nginx+uwsgi 部署django
安装nginx:
sudo apt-get install nginx
启动nginx:
sudo /etc/init.d/nginx restart
sudo /etc/init.d/nginx stop
sudo /etc/init.d/nginx start
测试nginx:
打开浏览器 输入: localhost:80 (默认80端口)
安装uwsgi:
进入虚拟环境安装: pip install uwsgi
测试uwsgi:
项目环境中 创建test.py文件:
def application(environ, start_response):
status = '200 OK'
output = 'Hello World! powerde by wsgi'
response_headers = [('Content-type', 'text/plain'),('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
运行 : uwsgi --http :8001 --wsgi-file test.py
然后浏览器访问 :http://127.0.0.1:8001
显示 :Hello World! powerde by wsgi
参考配置(/home/ysz/OnlineMx/xxx.ini)
[uwsgi]
http=127.0.0.1:8000
socket=127.0.0.1:8000
chdir=/home/ysz/OnlineMx
chmod-socket=664
master=true
processes=4
threads=2
module=OnlineMx.wsgi
wsgi-file=uwsgi_test.py
stats=127.0.0.1:9000
/etc/nginx/sites-enabled/default 文件如下
server {
listen 80;
server_name localhost; # substitute your machine's IP address or FQDN
client_max_body_size 75M; # adjust to taste
location /media {
alias /home/ysz/OnlineMx/uploadimage/; # your Django project's media files - amend as required
}
location /static {
alias /home/ysz/OnlineMx/staticBUSHU/; # your Django project's static files - amend as required
}
location / {
include uwsgi_params; # the uwsgi_params file you installed
uwsgi_pass 127.0.0.1:8000;
}
}
nginx 相关文章:
https://www.cnblogs.com/paul8339/tag/nginx/
参考地址:
https://www.cnblogs.com/leexl/p/7810843.html
http://www.cnblogs.com/jhao/p/6071790.html