简体   繁体   中英

Automatically redirected without proxy pass name while serving static files in express node js on apache2 server

I'm currently using apache2 on Ubuntu Server, and host node js apps with Proxy Pass Configuration in apache2 sites-available configuration.

I added this line in my server configuration

 ProxyPass /nodeapps http://localhost:3000

But when I'm trying to serve static files in my public directory like this,

 app.use(express.static(__dirname + '/public'));

It was automatically redirected without the proxypass name, so when I'm trying to open my

http://server-dns/nodeapps/help

I expect to get my /public/help directory, but it automatically redirected to

http://server-dns/help

So it return 404 Error

Not Found

The requested URL /help/ was not found on this server.

As you specified in comment, it seems to either index.html is not available in sysadmin/nodejsapps/nodeapps/public/help/ directory or problem in static path because your url http://server-dns/help is correct. So cross check bellow 2 points

Is sysadmin/nodejsapps/nodeapps/public/help/index.html exist ?
Is correct path used for static? You may like to use path module as bellow

var path = require('path');
app.use(express.static(path.join(__dirname, 'public')));

I hope this help you ):

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM