【发布时间】:2016-04-16 11:01:03
【问题描述】:
我有一个 Node.js 应用程序在端口 3000 上运行并使用 NGINX 作为代理。 NGINX 也提供静态文件。 sites-enabled 中的 conf:
server {
listen 80;
server_name myapp.dev;
location ~ ^/(img/|js/|css/|robots.txt|favicon.ico) {
root /srv/nodejs/myapp/public;
access_log off;
expires max;
}
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
目前一切正常。但是当请求一个不存在的静态文件(/css/doesntexist.css)时,我会得到一个默认的 NGINX 404 页面。
我知道可以将用户重定向到自定义 404 页面(例如 /404.html),但我希望在从我的 Node 应用程序显示自定义 404 时保持 URL 指向不存在的路径。
有什么想法吗?
【问题讨论】:
-
您是否尝试过使用
error_page? -
感谢您的提示。我想我应该有 RTFM。