【发布时间】:2021-05-23 16:08:11
【问题描述】:
我似乎无法弄清楚我在这个简单的设置中做错了什么,所以我设置了一个节点应用程序(测试起来超级简单),如下所示:
// import express
const express = require('express');
// create new express app and assign it to `app` constant
const app = express();
// server port configuration
const PORT = 3000;
// create a route for the app
app.get('/', (req, res) => {
res.send('Hello this seems to work!');
});
// server starts listening the `PORT`
app.listen(PORT, () => {
console.log(`Server running at: http://localhost:${PORT}/`);
});
我的 nginx 服务器配置看起来像这样
server {
listen 80;
server_name www.example.org;
#add in ssh details here later
#These lines create a bypass for certain pathnames
#www.example.com/test.js is now routed to port 3000
#instead of port 80
location ~* \.(js)$ {
proxy_pass http://localhost:3000;
# proxy_set_header Host $host;
}
}
现在根据我的说法,当我运行它时 - nginx 应该重定向以表示总是是的?但是当我访问该网站时,我一直看到欢迎使用 nginx 页面 - 而不是“你好,这似乎有效!”
我关注了这个页面,因为它有类似的静态文件案例,比如我 Express + Nginx. Can't serve static files
【问题讨论】: