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程式本身沒有問題
伊谢尔伦2017-05-24 11:34:53
我的理解是try_files 如果不成功,應該讓express伺服器嘗試回應
location / {
root /home/ubuntu/card/public; try_files $uri $uri/ @proxy; }
location @proxy {
proxy_pass http://127.0.0.1:3000;
}
漂亮男人2017-05-24 11:34:53
假設你的目錄/home/ubuntu/card/public
下方有個叫uploads的資料夾,nginx設定如下
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
location / {
proxy_pass http://127.0.0.1:3000;
}
location /uploads {
root /home/ubuntu/card/public/;
index index.html index.htm index.nginx-debian.html;
try_files $uri $uri/ =404;
}
}
那麼訪問http://localhost/會跳到nodejs,http://localhost/uploads/會訪問/home/ubuntu/card/public/uploads
下的靜態檔案。