0

我正在使用 Express 4.10、nginx、ubuntu 16.04 LTS,我想在我的公用文件夹中创建一个 javascript 文件夹。

public/js/myfile.js

我在 stackoverflow 上看到很多关于此的问题,但我的 javascript 文件中总是出现 404。

然后这是我的html代码:

<script src="js/login.js" type="text/javascript"/>

在我的 node.js 文件中,我有这个:

app.use(express.static(path.join(__dirname, '/public')));

这是我的 nginx 节点配置

upstream node {
    server 127.0.0.1:3000;
    keepalive 8;
}

location ~ ^/(node|socket\.io) {
    proxy_pass http://example.com: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;
}

谢谢。

4

1 回答 1

0

脚本源应该是类似的/node/public/js/myfile.js,否则 nginx 不会通过请求来表达。

于 2016-07-25T18:09:50.713 回答