只是记录一下,网上教程很多:
1、修改nginx配置文件
server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; root /home/ranvane/gwdj; index index.html index.htm; # Make site accessible from http://localhost/ server_name localhost; access_log /home/ranvane/gwdj/python.access.log; error_log /home/ranvane/gwdj/python.error.log; location / { proxy_pass http://127.0.0.1:8000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /static/{ root /home/ranvane/gwdj; #Django项目所在目录 expires 30d; break; } }
2、修改djnago的setting文件,设置为部署模式:
DEBUG = TEMPLATE_DEBUG = False if DEBUG: ALLOWED_HOSTS = [""] else: ALLOWED_HOSTS = ["localhost","127.0.0.1"]
3、使用gunicorn部署
gunicorn -b 0.0.0.0:8000 --workers=2 --log-file error.log wsgi&
时间: 2024-10-31 10:48:11