2013-10-14 105 views
1

我已經設置nginx來提供我的節點網絡應用程序(api + web),但正如我所看到的服務器只響應「/」(網絡根)呼叫。 當我測試它時,我看到主網頁(位於/index.html),但沒有圖像或css樣式,還有路徑/ api/v1/....中的api(/ api/v1/users ,/ api/v1/cars等)無法到達,因爲nginx響應「找不到」。Nginx和node.js路由問題

目前nginx的配置是:

server { 
    listen 80; 
    server_name localhost www.mydomain.com mydomain.com 

    access_log off; 
    error_log off; 

    location =/{ 
     proxy_pass http://127.0.0.1:3000; 
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
     proxy_set_header X-Real-IP $remote_addr; 
    } 
} 

我怎樣才能以服務的所有路由配置nginx的?

回答

2

要匹配所有路線,請放下=標誌。前綴爲=的指令將完全匹配查詢。更多的信息可以發現here

location/{ 
    proxy_pass http://127.0.0.1:3000; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header X-Real-IP $remote_addr; 
} 

這裏的樣品從文檔:

location =/{ 
    # matches the query/only. 
    [ configuration A ] 
} 
location/{ 
    # matches any query, since all queries begin with /, but regular 
    # expressions and any longer conventional blocks will be 
    # matched first. 
    [ configuration B ] 
} 
+0

糟糕!你是對的。非常感謝你 – Endymion