Sha*_*son 5 apache node.js express
我有一个在 CentOS 上运行的节点服务器,目前,您只需转到根目录中的任何文件并查看它,例如xxx.net/whatever.js
. 这显然不是很好,因为我在某些文件中有一些敏感信息。
如何禁止用户从浏览器导航到这些文件?
我设置了一个 apache 代理来查看该站点
<VirtualHost *:80>
ServerAdmin me@xxx.net
ServerName www.xxx.net
ServerAlias xxx.net
DocumentRoot /var/www/xxx.net
<Directory /var/www/xxx.net>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/www/xxx.net/error.log
CustomLog /var/www/xxx.net/requests.log combined
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Full
<Proxy *>
Require all granted
</Proxy>
<Location />
ProxyPass http://127.0.0.1:4000/
ProxyPassReverse http://127.0.0.1:4000/
</Location>
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
然后 pm2 运行一个快速节点服务器。我已经尝试了各种 chmod'ing,但没有任何改变。如果有人能阐明我的问题,那就太好了。如果您需要更多信息,请告诉我,谢谢!
您可以使用 express js 限制访问。
当这写成
app.use('/', express.static(__dirname));
Run Code Online (Sandbox Code Playgroud)
这意味着访问任何东西
您可以仅使用
app.use('/', express.static(__dirname + '/public'));
Run Code Online (Sandbox Code Playgroud)
或者你可以在 express 中编写中间件,它可以包含要阻止的文件路由列表
app.use(function (req, res, next) {
if(!checkFunction(req.url)) {
next();
} else {
res.send(404, "Not found");
}
})
var checkFunction(url){
var blockedUrl = ['folder/file1.js'];
return blockedUrl.find(function(urlCheck){
return urlCheck === url;
})
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2846 次 |
最近记录: |