時間: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項目中的靜態(tài)文件: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重啟所有管理的應(yīng)用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. 配置阿里云安全組關(guān)鍵詞:訪問,把手,部署
微信公眾號
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。