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

Chr*_*ris 4 gis django nginx gunicorn

我正在尝试托管一个由django应用程序和由tilestache提供服务的地图图块组成的网站.我可以使用其中任何一个让它们分别运行和提供内容

gunicorn_django -b 0.0.0.0:8000 
Run Code Online (Sandbox Code Playgroud)

对于django应用程序,或

gunicorn "TileStache:WSGITileServer('tilestache.cfg')"
Run Code Online (Sandbox Code Playgroud)

对于tilestache.我已经尝试了daemonizing django应用程序并在另一个端口(8080)上使用tilestache进程同时运行它们,但是tilestache不起作用.我认为问题在于我的nginx conf:

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;
}
Run Code Online (Sandbox Code Playgroud)

我可以server在conf中添加另一个块proxy_pass http://localhost:8080/吗?另外,我很新的这堆(我上大大依赖阿德里安Deccico的教程在这里得到Django的部分运行起来),所以任何'哇这是一个明显的错误’或建议,将不胜感激.

Tis*_*sho 8

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

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/;
}
Run Code Online (Sandbox Code Playgroud)

但随后为其他应用添加另一个位置:

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/;
}
Run Code Online (Sandbox Code Playgroud)

这里唯一的区别是港口.这样domain.com/tilestache将被处理localhost:8080,而所有其他地址将默认为django app at localhost:8000.放在location /tilstache前面location /.

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

upstream django_backend  {
  server localhost:8000;
}

upstream tilestache_backend  {
  server localhost:8080;
}
Run Code Online (Sandbox Code Playgroud)

然后在location部分中,使用:

location / {
    .....
    proxy_pass  http://django_backend;
}

location /tilestache {
    .....
    proxy_pass  http://tilestache_backend;
}
Run Code Online (Sandbox Code Playgroud)