Jus*_*tin 5 django nginx url-rewriting django-admin
我有一个名为django-admin的应用程序myapp,我希望在不同的物理盒上部署多个实例,每个客户一个.但是,我希望所有人都可以从类似的域访问它们mydomain.com/customer1/myapp.
我已经摆弄了特定的代理设置,并在SO上尝试了多项建议,但没有一个非常适合我的用例...因为我对两者都知之甚少nginx而且django我不知所措!
我目前的nginx.conf是:
server {
listen 80;
server_name myserver.com
location ^~ /static {
alias /path/to/static/files/;
}
# location / {
# proxy_pass http://127.0.0.1:8001;
# }
location ^~ /customer1/myapp/static {
alias /path/to/static/files/;
}
location /customer1/myapp {
rewrite ^/customer1/myapp/(/?)(.*) /$2 break;
proxy_pass http://127.0.0.1:8001;
}
}
Run Code Online (Sandbox Code Playgroud)
我可以通过预期进入登录屏幕myserver.com/customer1/myapp/admin.但是,当我尝试登录时,nginx会将我的网址重写myserver.com/admin为不是有效的网址.如何让nginx实际重写url并仅更改传递给的url 127.0.0.1:8001?
FWIW,我正在使用gunicorn服务gunicorn -b 127.0.0.1:8001 -n myapp.如果我取消注释/位置并删除最后两个位置块,那么该应用程序效果很好.
如果有其他选择,我对这种方法的态度还很远.目标是避免为每个部署修改django代码,而只是为nginx.conf添加最少的代码以用于新部署.
cob*_*aco 17
基本上,您指定url作为proxy_pass指令的一部分,以下位置指令应该这样做:
location ~ ^/customer1/myapp(/?)(.*) {
proxy_pass http://127.0.0.1:8001/$2;
}
Run Code Online (Sandbox Code Playgroud)
有关nginx如何通过uri的详细说明,请参见http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass
| 归档时间: |
|
| 查看次数: |
9272 次 |
| 最近记录: |