【发布时间】:2014-08-18 19:50:00
【问题描述】:
我有一个 django 项目,我想根据它正在访问的子域显示不同的内容,例如,当用户输入 url:http://e1.example.com/ 它显示 «Welcome to e1 site»,当用户输入:http://e2.example.com 时会显示«Welcome to e2 site»等等。
所以我有这个 nginx 配置:
upstream example_project{
server localhost:8200;
}
server {
listen 80;
server_name ~^(?<event>.+)\.example\.com;
location / {
proxy_pass http://example_project/$event$request_uri;
}
}
我有我的/etc/hosts 文件,如下所示:
127.0.0.1 example.com
127.0.0.1 e1.example.com
127.0.0.1 e2.example.com
当我转到 http://localhost:8200/e1/ 时它可以工作,但是当我转到 http://e1.example.com/ 时它显示 400 错误
在 django 控制台输出我有:
[18/Aug/2014 14:33:31] "GET /e1/ HTTP/1.1" 200 39 <-- this when going localhost:8200/e1/
[18/Aug/2014 14:33:33] "GET /e1/ HTTP/1.0" 400 26 <-- this when going e1.example.com
所以我可以看到e1.example.com 正在调用我的项目正确的 URL,但是为什么浏览器会显示 400 错误?
【问题讨论】:
标签: python django nginx localhost subdomain