2013-07-04 32 views
0

我有一個在本地機器上開發的ember.js應用程序。我使用restify/node.js服務器使其在本地可用。ember.js應用程序不會使用NGINX服務器更新URI的hashtag部分

當我在我的應用程序瀏覽,地址欄的變化是這樣的:

例1

1. http://dev.server:3000/application/index.html#about 
2. http://dev.server:3000/application/index.html#/items 
3. http://dev.server:3000/application/index.html#/items/1 
4. http://dev.server:3000/application/index.html#/items/2 

我現在試着將它部署到它運行nginx的一個遠程測試服務器上。

儘管本地一切正常,但我可以導航到我的Web應用程序,但是標籤後的URI部分未更新。

在任何瀏覽器中:http://test.server/application/index.html總是顯示在我的地址欄中。對於點擊的相同順序在爲例1,我總是有:

1. http://web.redirection/application/index.html 
2. http://web.redirection/application/index.html 
3. http://web.redirection/application/index.html 
4. http://web.redirection/application/index.html 

而且,如果我直接輸入完整的URI http://web.redirection/application/index.html#/items/1瀏覽器將只顯示在http://test.server/application/index.html(這絕對不是內容預期的行爲)。

我想這是來自我的NGINX配置,因爲該應用程序在本地restify服務器上完美工作。

此服務器

NGINX配置是:

test.server.conf(其被鏈接到/etc/nginx/sites-enabled/test.server.conf)

server { 
     server_name test.server web.redirection; 

     root /usr/share/nginx/test; 
     index index.html index.htm; 

     location/{ 
      try_files $uri $uri/ /index.html; 
     } 

     location ~ \.csv$ {  
      alias /usr/share/nginx/test/$uri; 
     } 
    } 

nginx.conf

user www-data; 
worker_processes 4; 
pid /var/run/nginx.pid; 

events { 
    worker_connections 768; 
} 

http { 
    sendfile on; 
    tcp_nopush on; 
    tcp_nodelay on; 
    keepalive_timeout 65; 
    types_hash_max_size 2048; 

    include /etc/nginx/mime.types; 
    default_type application/octet-stream; 

    access_log /var/log/nginx/access.log; 
    error_log /var/log/nginx/error.log debug; 

    gzip on; 
    gzip_disable "msie6"; 


    include /etc/nginx/conf.d/*.conf; 
    include /etc/nginx/sites-enabled/*; 
} 

編輯: 只是可以肯定,有我的測試服務器上沒有丟失的文件:我跑的RESTify /點頭e服務器(如我的開發機器)和一切工作正常當我連接到此服務器(!)。 nginx和restify服務器都指向相同的文件。

EDIT 2

我發現,當我使用網絡重定向我的問題發生。 如果我使用像http://test.server/application/index.html這樣的地址,一切正常 如果我使用http://web.redirection/application/index.html它不起作用。

所以這是我的nginx conf,它沒有正確地將web.redirection URI重定向到test.server或類似的東西。

有人有想法嗎?我錯過了什麼?我應該改變什麼來完成這項工作?

EDIT 3和溶液

我使用的Web重定向是A型DNS記錄。這不起作用。使用CNAME類型的DNS記錄解決了這個問題。

+0

你能確認你的應用程序應用程序所需的所有文件都正確部署到'/ usr/share/nginx/test'嗎? – intuitivepixel

+0

是的,我可以證實這一點:我做了幾個git克隆和那些不工作的是在遠程服務器上 – lauhub

回答

0

問題出在從web.redirection到test.server的DNS重定向。

這是一個A型記錄:這不起作用。

使用直接指向test.server工作的CNAME類型記錄。

1

不,這與nginx無關,任何通過#的東西永遠不會發送到服務器,JavaScript代碼應該處理這個問題,我會建議使用firebug或任何檢查器來確保所有的js文件正在加載,沒有任何404錯誤失敗,還檢查控制檯控制檯上的控制檯錯誤。

+0

+1添加LOG_TRANSITIONS:真正到您的應用程序,並查看路由器是否正在轉換,因爲您在瀏覽應用程序時期望。生產中很可能有一些當地可用的資源不存在。 –

+0

是的,它正在按預期轉換。一切都在生產中可用。爲了檢查這一點,我在測試服務器上運行了一個restify服務器,該服務器指向與nginx服務器的路徑完全相同的代碼:一切正常!所以我真的相信(即使我同意#之後的部分不應該發送到服務器),這是來自nginx。可能是我的規則過濾了一些不應該的東西? – lauhub

+0

好的,我很抱歉,因爲我錯過了一些我認爲可能會導致問題的東西:我實際上有一個Web重定向,正如我在編輯中所解釋的,當我使用它時出現問題(使用服務器名稱時問題消失) – lauhub

相關問題