2012-07-17 82 views
4

我想承载一个网站,由django应用程序和tilestache服务的地图瓷砖组成。我可以让他们运行,并通过使用Nginx conf为两个gunicorn应用程序(django和tilestache)

gunicorn_django -b 0.0.0.0:8000 

为Django应用程序,或

gunicorn "TileStache:WSGITileServer('tilestache.cfg')" 

为tilestache分别提供内容服务。我已经尝试守护django应用程序,并在不同的端口上使用tilestache进程同时运行它们(8080),但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; 
} 

我可以只添加其他server块在conf为proxy_pass http://localhost:8080/?此外,我对这个堆栈非常陌生(我非常依赖Adrián Deccico的教程here来让django部分启动并运行),所以任何“哇,这是一个明显的错误”或建议将不胜感激。

+0

您将如何区分这两个应用 - 他们使用不同的领域 - 像www.mydjangoapp.com和www.mytilestache.com?或者他们共享相同的域名,但使用不同的/路径/? – Tisho 2012-07-17 07:46:19

+0

@Tisho相同的域名,不同的路径。我已经看到了很多地图示例,它们将tile服务器放在子域上,并且可以开放。 – Chris 2012-07-17 07:48:44

回答

8

据我所知 - 您已将location /映射到localhost:8000。当你有两个不同的上游时,你需要两个不同的位置映射,每个上游一个。 所以假设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/; 
} 

但再添加其他位置的其他应用程序:

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/; 
} 

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

为清楚起见,你可以定义你的上行信是这样的:

upstream django_backend { 
    server localhost:8000; 
} 

upstream tilestache_backend { 
    server localhost:8080; 
} 

,然后在location部分,使用:

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

location /tilestache { 
    ..... 
    proxy_pass http://tilestache_backend; 
} 
+1

美丽!那很完美。 – Chris 2012-07-17 08:15:47

+1

非常感谢。经过大量搜索后,这对我来说就解决了 – Avinash 2012-10-04 05:15:21

相关问题