服务器配置django + uwsgi +nginx
第一步:
在django项目目录下生成“项目名_uwsgi.ini”配置文件:
[uwsgi] http = :9000 #the local unix socket file than commnuincate to Nginx socket = 127.0.0.1:8001 # the base directory (full path) chdir = /webapps/hello_django/hello # Django's wsgi file wsgi-file = hello/wsgi.py # maximum number of worker processes processes = 4 #thread numbers startched in each worker process threads = 2 #monitor uwsgi status stats = 127.0.0.1:9191 # clear environment on exit vacuum= true #django所在位置的上一级目录 pythonpath = /webapps/hello_django/lib/python3.6/site-packages
2.将nginx 目录下的uwsgi_params文件拷贝到django项目目录
3.在Django项目目录下生成nginx配置文件 项目名_nginx.conf
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 192.168.1.122; # 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 /webapps/hello_django/hello/media; # your Django project's media files - amend as required
}
location /static {
alias /webapps/hello_django/hello/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 /webapps/hello_django/hello/uwsgi_params; # the uwsgi_params file you installed
}
}
4.做一个软连接到/etc/nginx/sites-enabled
sudo ln -s ~/path/to/your/mysite/mysite_nginx.conf /etc/nginx/sites-enabled/
5.python manage.py collectstatics 把所有的静态文件拷贝到统一的目录
#在settings中配置static_rootSTATIC_ROOT=os.path.join(BASE_DIR,"all_statics/")
#2.run (提示输入yes) python manage.py collectstatic
#3.现在我们需要去修改nginx的配置文件,将静态文件的目录修改为汇聚后的静态文件的目录location/static {
alias /usr/local/Django_test/all_statics; }现在去启动nginx和uwsgi
6.重启nginx:
sudo /etc/init.d/nginx start # start nginx
7.重启uwsgi
uwsgi hello_uwsgi.ini
浙公网安备 33010602011771号