简体   繁体   English

在apache2服务器上的快速节点js中提供静态文件时,自动重定向而不使用代理传递名称

[英]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. 我目前在Ubuntu Server上使用apache2,在apache2站点中使用代理传递配置的主机节点js应用程序 - 可用配置。

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 我希望得到我的/ public / help目录,但它会自动重定向到

http://server-dns/help

So it return 404 Error 所以它返回404错误

Not Found 未找到

The requested URL /help/ was not found on this server. 在此服务器上找不到请求的URL / help /。

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. 正如您在注释中指定的那样,似乎index.htmlsysadmin/nodejsapps/nodeapps/public/help/目录中不可用或静态路径中存在问题,因为您的URL http:// server-dns / help是正确的。 So cross check bellow 2 points 所以交叉检查2点

Is sysadmin/nodejsapps/nodeapps/public/help/index.html exist ? sysadmin/nodejsapps/nodeapps/public/help/index.html存在?
Is correct path used for static? 是否使用正确的静态路径? You may like to use path module as bellow 您可能希望使用path模块

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

I hope this help you ): 我希望这能帮到你):

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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