2017-02-23 57 views
0

我試圖安裝在nginx的一個作出反應的應用程序,但是從一個子目錄提供靜態文件時,我面臨的一個問題Nginx的404(反應的應用程序)

我的文件樹是這樣的:

/var/www/ 
    antoinedeveyrac.io/ 
    ... 
    react/ 
    ... 
    build/ 
     index.html 
     static/ 
     js 
      *.js 
     css 
      *.css 

我的conf文件是:

server { 
    listen 443 ssl http2; 
    listen [::]:443 ssl http2; 
    include snippets/ssl-antoinedeveyrac.io.conf; 
    include snippets/ssl-params.conf; 

    root /var/www/antoinedeveyrac.io/html; 
    index index.html index.htm index.nginx-debian.html; 

    server_name antoinedeveyrac.io www.antoinedeveyrac.io; 

    location/{ 
     # First attempt to serve request as file, then 
     # as directory, then fall back to displaying a 404. 
     try_files $uri $uri/ =404; 
    } 

    location ~ /.well-known { 
     allow all; 
    } 

    location /react { 
     alias /var/www/react/build; 
     try_files $uri $uri/ =404; 
     autoindex off; 
     index index.html; 
    } 
} 

所以,當我打https://antoinedeveyrac.io/react,我有那些404錯誤,這意味着nginx的不明白,我想從服務文件而不是https://antoinedeveyrac.io/static/...

如何修復我的配置文件以匹配子目錄中的靜態文件?非常感謝:)

回答

0

你是否在/var/www/react/build/index.html中引用的資產或index.html頁面上獲得了404的資源?我會在評論中提出這個問題,但代表還不夠高。

根據您發佈的目錄輸出,您的nginx根配置指向一個看起來不存在的html目錄。

root /var/www/antoinedeveyrac.io/html; 

嘗試改變根config來......

root /var/www/antoinedeveyrac.io/ 

在您的index.html,您應該參考資產像這樣(如果你不這樣做的話)

<link href="scripts/somefile.css" rel="stylesheet"> 
相關問題