0
我使用Express 4.10,nginx,ubuntu 16.04 LTS,我想在我的公用文件夾中創建一個javascript文件夾。節點js javascript文件夾404找不到
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;
}
謝謝。
您是否嘗試在src的值開頭添加'/'? – mscdex
是的,但我有同樣的錯誤。我的服務器運行在Nginx上,也許問題是nginx端? – John
@John你記得把nginx代理到node嗎? http://stackoverflow.com/questions/5009324/node-js-nginx-what-now –