I once installed node and express via npm in my Windows laptop. I put my node_modules
folder in a same directory as my app.js
. Everything works fine including some attempt serving static files.
app.use('/static', express.static(path.join(__dirname, 'public')));
I can play with this directory, even with index.html
(auto-default page if I open /static/somedir
) and its style.css
.
Later, I tried to move it to my linux vps (node installed) to see how is it look like, it was proxied with nginx.
All my view works fine, but my .css
, and .js
extension files always return 404 .
I edited my /sites-available/default
config in nginx to take over static files
server {
listen 80;
server_name mysite;
location / {
proxy_pass http://myip:myport;
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;
}
}
solution found on https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-14-04
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.