摘要:安装创建文件创建配置文件启动也可编写启动脚本配置文件,添加下面一行内容在新建文件重新启动访问页面测试调试过程中,报错多多查看日志排错。
在开发环境下调试好python项目之后,把项目迁移到nginx上面 首先把django admin的静态文件目录复制一份到你设置的static文件目录下:
python manage.py collectstatic关闭settings.py中的debug,关闭debug之后staticfiles就不生效了,需要在nginx配置静态文件的访问。 安装uwsgi
pip install uwsgi创建wsgi文件:
root@server1 testweb]# pwd /Django/testweb [root@server1 testweb]# cat wsgi.py import os os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testweb.settings") from django.core.wsgi import get_wsgi_application application = get_wsgi_application()创建ini配置文件:
[root@server1 testweb]# pwd /Django/testweb [root@server1 testweb]# cat app.ini [uwsgi] chdir = /Django/testweb/ ;wsgi-file = /Django/testweb/wsgi.py module = testweb.wsgi socket = 127.0.0.1:3400 ;socket = /var/log/%(project).sock chmod-socket = 664 ;http = 0.0.0.0:8001 ;stats = 0.0.0.0:8001 master = true processes = 4 threads = 2 max-requests = 6000 vacuum = true pidfile = /var/log/uwsgi.pid; daemonize = /var/log/uwsgi.log启动uwsgi:
[root@server1 testweb]# uwsgi --ini app.ini也可编写uwsgi启动脚本:
[root@server1 ~]# cat /etc/init.d/uwsgi uwsgi_path=/usr/bin/uwsgi uwsgi_ini=/Django/testweb/app.ini uwsgi_pid=/var/log/uwsgi.pid if [ ! -n $1 ] then echo "Usages: [start|stop|restart]" exit 0 fi if [ $1 = start ] then psid=`ps aux | grep "zh" | grep -v "grep" | wc -l` if [ $psid -gt 4 ] then echo "uwsgi is running!" exit 0 else uwsgi --ini $uwsgi_ini echo "Start uwsgi service [OK]" fi elif [ $1 = stop ];then killall -s INT uwsgi echo "Stop uwsgi service [OK]" elif [ $1 = restart ];then #killall -s INT uwsgi #uwsgi --ini uwsgi_ini kill -HUP $uwsgi_pid echo "Restart uwsgi service [OK]" else echo "Usages: [start|stop|restart]" fi [root@server1 ~]# cat /etc/init.d/uwsgi uwsgi_path=/usr/bin/uwsgi uwsgi_ini=/Django/testweb/app.ini uwsgi_pid=/var/log/uwsgi.pid if [ ! -n $1 ] then echo "Usages: [start|stop|restart]" exit 0 fi if [ $1 = start ] then psid=`ps aux | grep "zh" | grep -v "grep" | wc -l` if [ $psid -gt 4 ] then echo "uwsgi is running!" exit 0 else uwsgi --ini $uwsgi_ini echo "Start uwsgi service [OK]" fi elif [ $1 = stop ];then killall -s INT $uwsgi_path echo "Stop uwsgi service [OK]" elif [ $1 = restart ];then #killall -s INT uwsgi #uwsgi --ini uwsgi_ini kill -HUP $uwsgi_pid echo "Restart uwsgi service [OK]" else echo "Usages: [start|stop|restart]" fi配置nginx.conf文件,添加下面一行内容:
include /usr/local/nginx/conf/conf.d/*;在conf.d新建app.conf文件:
[root@server1 conf.d]# cat app01.conf server { listen 80; server_name localhost; charset utf-8; access_log logs/testweb/app01/access_log; error_log logs/testweb/app01/error_log; client_max_body_size 75M; # adjust to taste #location /admin { #alias /Django/testweb/static/admin # } location /static { alias /Django/testweb/static; # your Django project"s static files - amend as required } # Finally, send all non-media requests to the Django server. location / { uwsgi_pass 127.0.0.1:3400; include uwsgi_params; # the uwsgi_params file you installed } }重新启动Nginx:
[root@server1 conf.d]# /etc/init.d/nginx stop [root@server1 conf.d]# /etc/init.d/nginx start访问页面测试:
调试过程中,报错多多查看日志排错。
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/41596.html
阅读 2194·2021-09-22 15:25
阅读 3591·2019-08-30 12:48
阅读 2154·2019-08-30 11:25
阅读 2306·2019-08-30 11:05
阅读 704·2019-08-29 17:28
阅读 3265·2019-08-26 12:16
阅读 2577·2019-08-26 11:31
阅读 1627·2019-08-23 17:08