多平台统一管理软件接口,如何实现多平台统一管理软件接口
298
2022-08-31
Django之项目部署(django项目部署到本地)
1.线上部署一般会使用install django-extensions django-werkzeug-debugger-runserver pyOpenSSL
2)添加配置项settings.py文件中
INSTALLED_APPS = [ 'werkzeug_debugger_runserver', 'django_extensions', 'corsheaders', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'mozilla_django_oidc',]
这样就可以使用启动命令来启动服务了
python manage.py runserver_plus 0.0.0.0:8000 --cert-file=/etc/certs/xxx.com.crt --key-file=/etc/certs/xxx.com.key
即可启动一个django3.0+提供了异步特性, 同时支持uvicorn的部署方式
2.supervisor+uvicorn+nginx部署
1)安装uvicorn
uvicorn采用了uvloop 用Cython改写了python里面asyncio的时间循环, 将asyncio的效率提高了4倍以上
pip3 install uvicorn
运行项目方式:
uvicorn [项目主目录].asgi.application 即可
2)安装supervisor, 这个的安装我之前的文章中也有详细的说明, 这里就略过
添加项目配置项:
[fcgi-program:xxx]socket=tcp://localhost:8000directory=/opt/xxx/command=/opt/xxx/env/bin/uvicorn --fd 0 xxx.asgi:application --ssl-certfile=/etc/certs/xxx.com_bundle.crt --ssl-keyfile=/etc/certs/xxx.com.keynumprocs=4autostart=trueprocess_name=service-%(process_num)dstdout_logfile=/var/log/supervisord/xxx.log ; stdout log path, NONE for none; default AUTOstdout_logfile_maxbytes=100MB ; max # logfile bytes b4 rotation (default 50MB)stdout_logfile_backups=10 ; # of stdout logfile backups (0 means none, default 10)stderr_logfile=/var/log/supervisord/xxx_error.log ; stderr log path, NONE for none; default AUTOstderr_logfile_maxbytes=100MB ; max # logfile bytes b4 rotation (default 50MB)stderr_logfile_backups=10 ; # of stderr logfile backups (0 means none, default 10)
说明:
socket为对外暴露的接口 可以是unix 也可以是一个网络端口 端口的形式可以见官方文档
command为执行命令
directory为项目路径
numprocs是处理器个数
process_name是处理进程的名称
添加完成之后, 更新supervisor
supervisorctl update # 更新配置supervisorctl start uvicorn:*supervisorctl stop uvicorn:*supervisorctl restart uvicorn:**的作用是所有进程:start Start a processstart :* Start all processes in a groupstart Start multiple processes or groupsstart all Start all processes
3)nginx配置
配置文件中添加反向代理
1){ listen 80; server_name localhost charset UTF-8; access_log /home/log/xxx_access.log; error_log /home/log/xxx_error.log; client_max_body_size 75M; location / { proxy_pass }}
2){ listen 443 ssl; server_name xxx.com; access_log /var/log/nginx/xxx.com_access.log main; error_log /var/log/nginx/xxx.com_error.log warn; ssl_certificate /etc/certs/xxx.com_bundle.crt; ssl_certificate_key /etc/certs/xxx.com.key; ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; location / { root /opt/XXX/dist; index index.html; #proxy_pass proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location ~ ^/(admin|user|oidc|backend|astatic) { proxy_pass_header Server; proxy_set_header Host $ proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_pass proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }}
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~