nginx 服務 AngularJS 應用程式傳回 404 Not Found

nginx 服務 AngularJS 應用程式傳回 404 Not Found

我在配置 nginx 來提供靜態 angularjs 檔案時遇到問題。

這是我的情況,我希望我的應用程式的登陸頁面位於

domain.com

以及下面的 AngularJS 應用程式

domain.com/app

現在我正在努力解決 nginx 設定問題。我建立了一個 nginx 伺服器配置,如下所示:

server {
    listen   80; ## listen for ipv4; this line is default and implied

    index index.html index.htm;

    server_name domain.com www.domain.com;

    location / {
            root /usr/share/nginx/html/domain.com;
    }

    location /app {
        alias /usr/share/nginx/html/domain.com/app/public;
    }
}

但這不起作用,我在 Firebug 上收到此錯誤:

"NetworkError: 404 Not Found - http://domain.com/app/"

任何想法?


好吧,如果我更改以下內容,我取得了一些進展:

alias /usr/share/nginx/html/domain.com/app/public;

至以下內容:

alias /usr/share/nginx/html/domain.com/app/public/;

(如果我使用 root 而不是別名,則會收到 403 禁止)

我現在可以訪問該應用程序,但資產文件上仍然有 404,例如其中之一是:

"NetworkError: 404 Not Found - http://example.com/app/assets/images/logo.png"

資產位於目錄下:

/usr/share/nginx/html/example.com/app/public/app/assets/

但由於某種原因 nginx 正在這裡尋找資產:

/usr/share/nginx/html/example.com/app/public/assets/

任何想法?

相關內容