uwsgi django部署
django debug=True下,静态文件处理
django.contrib.staticfiles

# --insecure不稳定
python manage.py runserver --insecure 0.0.0.0:8000
debug=False
1、uwsgi
python manage.py collectstatic
uwsgi --ini uwsgi.ini
uwsgi --stop uwsgi.pid
ps aux | grep uwsgi
uwsgi.ini
[uwsgi]
# 使用Nginx连接时使用,Django程序所在服务器地址
# socket=ip:port
# 直接做web服务器使用,Django程序所在服务器地址
http=ip:port
#
buffer-size = 65536
# 项目目录
# chdir=项目路径
chdir= /root/demo/test_proj
# =前面的/static是uWSGI的URL前缀,而后面的/demo/static_test则是静态文件的路径
static-map = /static=/demo/static_test
# 项目中wsgi.py文件的目录,相对于项目目录
wsgi-file=/项目路径下的wsgi.py文件路径/wsgi.py
# 进程数
processes=4
# 线程数
threads=2
# uwsgi服务器的角色
master=True
# 存放进程编号的文件
pidfile=uwsgi.pid
# 日志文件
daemonize=/var/log/test_uwsgi.log
# 指定依赖的虚拟环境
virtualenv=/root/.virtualenvs/test_env
wsgi.py
"""
WSGI config for meiduo_mall project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_search_proj.settings.prod")
application = get_wsgi_application()
2、static.serve
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static_test')
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
]
from django.conf import settings # 新加
from django.conf.urls import url # 新加
from django.urls import path
from django.views import static # 新加
from django_search_proj.extra_apps import xadmin
xadmin.autodiscover()
# version模块自动注册需要版本控制的 Model
urlpatterns = [
path('', xadmin.site.urls),
# 新加
url(r'^static/(?P<path>.*)$', static.serve,
{'document_root': settings.STATIC_ROOT}, name='static'),
path('admin/', xadmin.site.urls),
]