首页 > 代码库 > 如何将django部署从顶级目录迁移到子目录下(NGINX UWSGI DJANGO)
如何将django部署从顶级目录迁移到子目录下(NGINX UWSGI DJANGO)
因为公司网站合并,要将我们的DJANGO项目从IP的顶级目录迁移到域名的二级目录。
以前硬编码的URL可惨了。
还涉及到upload目录,静态目录,websocket目录.
全用{% url %}问题不太大。
nginx分前后两级,uwsgi配置要作相应更改,django的setting需要变量登陆网址。
这样,在正式网站访问二级目录,测试环境仍然可以根目录访问。
nginx_front:
server { listen 80; server_name localhost; location /prism/ { proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://prism_host; client_max_body_size 1000m; client_body_timeout 5m; proxy_connect_timeout 5m; proxy_read_timeout 5m; proxy_send_timeout 5m; } location /prism/websocket { proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; proxy_pass http://websocket_host; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } }
nginx_back:
server { listen 80; server_name localhost; location /prism/ { include uwsgi_params; uwsgi_pass prism_host; uwsgi_param SCRIPT_NAME /prism; uwsgi_modifier1 30; index index.html index.htm; client_max_body_size 1000m; client_body_timeout 5m; proxy_connect_timeout 5m; proxy_read_timeout 5m; proxy_send_timeout 5m; } location /prism/ws_log { proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; proxy_pass http://websocket_host; } location ^~ /prism/static { alias /Prism/static; } }
uwsgi.ini
[uwsgi]socket = 10.1.1.11:9090chdir = /Prismmodule = settings.wsgimaster = truevhost = trueno-stie = trueworkers = 4reload-mercy = 10vacuum = true max-requests = 1000limit-as = 512buffer-sizi = 30000pidfile = /var/log/prism/uwsgi9090.pid daemonize = /var/log/prism/uwsgi9090.loglisten=1024
setting.py(生产)--测试的settings.py不用变更
LOGIN_URL = ‘/prism/accounts/login‘STATIC_URL = ‘/prism/static/‘
然后,大功告成!
如何将django部署从顶级目录迁移到子目录下(NGINX UWSGI DJANGO)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。