Sails.js 0.10.x:如何仅在本地主机上收听? [英] Sails.js 0.10.x: How to listen on localhost only?
本文介绍了Sails.js 0.10.x:如何仅在本地主机上收听?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过 NGINX 代理管理所有流量,并确保无法从外部直接访问节点服务器.
I would like to pipe all traffic through an NGINX proxy and make sure that the node server won't be accessible directly from the outside.
Node 的 http 模块只能在 localhost 上侦听给定端口,是否有选项可以启用 Sails.js 来做同样的事情?
Node's http module has the ability to listen on a given port on localhost only, is there an option to enable sails.js to do the same?
推荐答案
只需添加这一行:
config/local.js
explicitHost: process.env.HOST ||'本地主机'
或者您可以添加策略:
config/policies.js
module.exports.policies = {
'*': 'isLocal'
}
api/policies/isLocal.coffee
# sessionAuth
#
# @module :: Policy
# @description :: Accept only local connections
# @docs :: http://sailsjs.org/#!documentation/policies
module.exports = (req, res, cb) ->
if req.ip is '127.0.0.1' then cb()
else res.forbidden new Error 'Accept only local connections'
这篇关于Sails.js 0.10.x:如何仅在本地主机上收听?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文