时间:2023-02-08 00:52:01 | 来源:建站知识
时间:2023-02-08 00:52:01 来源:建站知识
平台:阿里云source /home/venv/bin/activatepip install gunicorn
4. 安装Nginxserver{ charset utf-8; listen 80; server_name 192.168.77.58; location /static { alias /home/Code/static; } location /media { alias /home/Code/media; } location /{ proxy_set_header Host $host; proxy_pass http://unix:/tmp/192.168.77.58.socket; } }
收集Django项目中的静态文件:python manage.py collectstatic
注意将Django项目中settings.py文件中DEBUG = FalseALLOWED_HOSTS = ['*']
以及将STATICFILES_DIRS改成STATIC_ROOT=os.path.join(BASE_DIR,'static')
将urls.py中的STATICFILES_DIRS也改成STATIC_ROOTpip install supervisor
supervisor的使用方法:Supervisor使用教程 - 飞鸿影 - 博客园[program:Code]command=/home/venv/bin/gunicorn --bind unix:/tmp/192.168.77.58.socket Code.wsgi:applicationdirectory=/home/Codeautostart=trueautorestart=truestdout_logfile=/home/Code/log/gunicorn.logstderr_logfile=/home/Code/log/gunicorn.err
6. 配置阿里云安全组ps -ef | grep supervisor(进程名称)kill 进程号
启动nginxnginx
nginx重新加载配置文件nginx -s reload
启动supervisorsupervisord
supervisor更新新的配置supervisorctl update
supervisor重启所有管理的应用supervisorctl reload
server{ charset utf-8; listen 80; server_name www.code.com; location /static { alias /home/Code/static; } location /media { alias /home/Code/media; } location /{ proxy_set_header Host $host; proxy_pass http://unix:/tmp/www.code.com.socket; } }
3. supervisor配置[program:Code]command=/home/venv/bin/gunicorn --bind unix:/tmp/www.code.com.socket Code.wsgi:applicationdirectory=/home/Codeautostart=trueautorestart=truestdout_logfile=/home/Code/log/gunicorn.logstderr_logfile=/home/Code/log/gunicorn.err
4. nginx和supervisor重新加载配置文件server{ charset utf-8; listen 443; server_name www.code.com; ssl on; ssl_certificate /etc/nginx/cert/code.com.pem; ssl_certificate_key /etc/nginx/cert/code.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 /static { alias /home/Code/static; } location /media { alias /home/Code/media; } location /{ proxy_set_header Host $host; proxy_pass http://unix:/tmp/www.code.com.socket; } } server{ listen 80; server_name www.code.com; rewrite ^(.*) https://$server_name$request_uri? permanent; }
3. 配置阿里云安全组关键词:访问,把手,部署