【发布时间】:2021-06-20 05:31:25
【问题描述】:
我使用 nginx 在同一域下提供静态 html 站点和 expressjs 应用程序。我的 nginx 配置如下所示:
location / {
try_files $uri $uri/ /index.html;
autoindex off;
root /var/www/example.com/static/;
}
location /admin {
proxy_pass http://localhost:3007/;
proxy_set_header Host $host;
proxy_buffering off;
autoindex off;
}
如果我访问 example.com/admin,我可以访问在端口 3007 上运行的应用程序,因此我的 app.get('/', routes.index); 似乎正在运行,但我在其他路线上运行时遇到了一些麻烦。
例如:
app.get('/admin/test', function(req, res) {
console.log("test!")
});
如果我尝试访问example.com/admin/test,根据我的日志,我只会看到Cannot GET //test 和404:
GET //test 404 11ms
如果我将路由更改为 /test,则会出现同样的问题。任何指针那里有什么问题。我还没有找到一种方法来使路由相对于它们安装到的基本路径 (/admin)。
谢谢!
【问题讨论】: