nginx的設定碼是這樣的
server {
listen 80 default_server;
listen [::]:80 default_server;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
root /home/ubuntu/card/public;
try_files $uri $uri/ =404;
proxy_pass http://127.0.0.1:3000;
}
}
node程式本身沒有問題
我的理解是try_files 如果不成功,應該讓express伺服器嘗試回應
假設你的目錄
/home/ubuntu/card/public
下方有個叫uploads的資料夾,nginx設定如下那麼訪問http://localhost/會跳到nodejs,http://localhost/uploads/會訪問
/home/ubuntu/card/public/uploads
下的靜態檔案。