2012-07-17 79 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

相關問題