背景
- 项目在内网部署,本来想使用nginx部署,因为某些原因,所以采用了Django+uwsgi+vue部署的部署方式
部署流程
Vue打包
- 执行
npm run lint-fix
- 执行
npm run build
- 将生成的包放到Django项目根目录的static目录下
Django配置
静态文件目录
| -- project/ |
| ..... |
| manage.py |
| -- static/ |
| .... |
| dist/ |
| index.html |
| ..... |
setting.py配置
| TEMPLATES = [ |
| { |
| 'BACKEND': 'django.template.backends.django.DjangoTemplates', |
| 'DIRS': [os.path.join(BASE_DIR, 'static/')], |
| 'APP_DIRS': True, |
| 'OPTIONS': { |
| 'context_processors': [ |
| 'django.template.context_processors.debug', |
| 'django.template.context_processors.request', |
| 'django.contrib.auth.context_processors.auth', |
| 'django.contrib.messages.context_processors.messages', |
| ], |
| }, |
| }, |
| ] |
| |
| STATIC_SAN = os.path.join(BASE_DIR, 'static/dist') |
路由配置urls.py
| urlpatterns = [ |
| |
| path(r'', TemplateView.as_view(template_name='index.html')), |
| |
| |
| url(r'^dist/(?P<path>.*)$', static.serve, {'document_root': settings.STATIC_SAN}, name='static'), |
| |
| ] |
| |
| |
| handler404 = page_not_found |
重写handler404
| from django.http import HttpResponseNotFound |
| from django.shortcuts import render |
| |
| |
| def page_not_found(request, exception): |
| return HttpResponseNotFound(render(request, 'index.html')) |
uwsgi配置和说明 pro.ini
| [uwsgi] |
| |
| chdir=/usr/local/pro/ |
| |
| |
| wsgi-file = pro/wsgi.py |
| master=True |
| home = /usr/local/python/python38 |
| |
| PYTHONHOME = /usr/local/python/python38/bin |
| |
| pidfile=/run/pro/pro.pid |
| vacuum=True |
| |
| max-requests=10000 |
| |
| daemonize=/tmp/pro/pro.log |
| |
| http=:8021 |
| |
| |
| env = LANG=en_US.UTF-8 |
| processes=2 |
| threads=4 |
| |
| enable-threads = true |
| |
| lazy-apps = false |
| |
| |
| static-map = /nis-console=static/nis-console |
| |
| log-maxsize = 50000000 |
| |
| |
运行uwsgi
uwsgi --ini /usr/local/pro/pro/pro.ini
停止运行
ps -ef |grep uwsgi|grep -v grep|awk '{print $2}'|xargs kill -9
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义