首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Nginx conf用于两个gunicorn应用程序(django和tilestache)

Nginx conf用于两个gunicorn应用程序(django和tilestache)
EN

Stack Overflow用户
提问于 2012-07-17 13:07:00
回答 1查看 3.1K关注 0票数 4

我正在尝试托管一个由django应用程序和tilestache提供的地图瓦片组成的网站。我可以使用以下任一方法让它们分别运行和提供内容

代码语言:javascript
复制
gunicorn_django -b 0.0.0.0:8000 

对于django应用程序,或者

代码语言:javascript
复制
gunicorn "TileStache:WSGITileServer('tilestache.cfg')"

是用来治疗瓷砖的。我曾尝试对django应用程序进行后台管理,并在不同的端口(8080)上与tilestache进程同时运行它们,但tilestache不起作用。我假设问题出在我的nginx conf中:

代码语言:javascript
复制
server {
    listen   80;
    server_name localhost;

    access_log /opt/django/logs/nginx/vc_access.log;
    error_log  /opt/django/logs/nginx/vc_error.log;

    # no security problem here, since / is alway passed to upstream
    root /opt/django/;
    # serve directly - analogous for static/staticfiles
    location /media/ {
        # if asset versioning is used
        if ($query_string) {
            expires max;
        }
    }
    location /static/ {
        # if asset versioning is used
        if ($query_string) {
            expires max;
        }
    }
    location / {
        proxy_pass_header Server;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Scheme $scheme;
        proxy_connect_timeout 10;
        proxy_read_timeout 10;
        proxy_pass http://localhost:8000/;
    }
    # what to serve if upstream is not available or crashes
    error_page 500 502 503 504 /media/50x.html;
}

我可以在proxy_pass http://localhost:8080/的conf中添加另一个server块吗?此外,我对这个堆栈非常陌生(我在很大程度上依赖于Adrián Deccico的教程here来启动和运行django部分),因此任何“哇,这是一个明显的错误”或建议将非常感谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-07-17 16:04:01

据我所知,您已经将location /映射到localhost:8000。当你有两个不同的上游时,你需要两个不同的位置映射,每个上游一个。因此,假设django应用程序是您的域上的主站点,您将拥有现在的默认位置:

代码语言:javascript
复制
location / {
    proxy_pass_header Server;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Scheme $scheme;
    proxy_connect_timeout 10;
    proxy_read_timeout 10;
    proxy_pass http://localhost:8000/;
}

然后为另一个应用程序添加另一个位置:

代码语言:javascript
复制
location /tilestache {
    proxy_pass_header Server;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Scheme $scheme;
    proxy_connect_timeout 10;
    proxy_read_timeout 10;
    proxy_pass http://localhost:8080/;
}

这里唯一的区别是端口。这样,域名.com/tilestache将由localhost:8080处理,而所有其他地址将默认使用localhost:8000上的django应用程序。将location /tilstache放在location /之前。

为了清楚起见,您可以这样定义您的上游:

代码语言:javascript
复制
upstream django_backend  {
  server localhost:8000;
}

upstream tilestache_backend  {
  server localhost:8080;
}

然后在location部分中,使用:

代码语言:javascript
复制
location / {
    .....
    proxy_pass  http://django_backend;
}

location /tilestache {
    .....
    proxy_pass  http://tilestache_backend;
}
票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11516308

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档