Sails.js 0.10.x:如何仅在本地主机上侦听?

Sails.js 0.10.x:如何仅在本地主机上侦听?,sails.js,Sails.js,我希望通过NGINX代理传输所有流量,并确保节点服务器不会直接从外部访问 Node的http模块只能在localhost上的给定端口上侦听,是否有允许sails.js执行相同操作的选项?不确定当您使用nginx作为代理服务器时,为什么要使用sails来限制对localhost的访问(nginx是为满足您的需要而设计的)。您可以使用nginx配置文件限制对Sails应用程序的本地访问 server { listen 80; server_name www.yourSailsAp

我希望通过NGINX代理传输所有流量,并确保节点服务器不会直接从外部访问


Node的http模块只能在localhost上的给定端口上侦听,是否有允许sails.js执行相同操作的选项?

不确定当您使用nginx作为代理服务器时,为什么要使用sails来限制对localhost的访问(nginx是为满足您的需要而设计的)。您可以使用nginx配置文件限制对Sails应用程序的本地访问

  server {
    listen 80;
    server_name www.yourSailsApp.com;
    ...
    location / {
      allow   127.0.0.1;
      deny    all;
    }
  }
您可能需要将站点添加到主机文件
/etc/HOSTS

127.0.0.1 yourSailsApp.com


或者,您可以在nginx配置中,在
允许
字段中找到服务器的公共IP并使用该IP。

不确定在使用nginx作为代理服务器时,为什么要使用Sails来限制对本地主机的访问(nginx的设计目的是满足您的需要)。您可以使用nginx配置文件限制对Sails应用程序的本地访问

  server {
    listen 80;
    server_name www.yourSailsApp.com;
    ...
    location / {
      allow   127.0.0.1;
      deny    all;
    }
  }
您可能需要将站点添加到主机文件
/etc/HOSTS

127.0.0.1 yourSailsApp.com


或者,您可以在nginx配置中,在
允许
字段中找到服务器的公共IP并使用该IP。

不确定在使用nginx作为代理服务器时,为什么要使用Sails来限制对本地主机的访问(nginx的设计目的是满足您的需要)。您可以使用nginx配置文件限制对Sails应用程序的本地访问

  server {
    listen 80;
    server_name www.yourSailsApp.com;
    ...
    location / {
      allow   127.0.0.1;
      deny    all;
    }
  }
您可能需要将站点添加到主机文件
/etc/HOSTS

127.0.0.1 yourSailsApp.com


或者,您可以在nginx配置中,在
允许
字段中找到服务器的公共IP并使用该IP。

不确定在使用nginx作为代理服务器时,为什么要使用Sails来限制对本地主机的访问(nginx的设计目的是满足您的需要)。您可以使用nginx配置文件限制对Sails应用程序的本地访问

  server {
    listen 80;
    server_name www.yourSailsApp.com;
    ...
    location / {
      allow   127.0.0.1;
      deny    all;
    }
  }
您可能需要将站点添加到主机文件
/etc/HOSTS

127.0.0.1 yourSailsApp.com

或者,您也可以在nginx配置中,在
允许
字段中找到服务器的公共IP并使用它。

只需添加以下行:

config/local.js

module.exports.policies = {
  '*': 'isLocal'
}
explicitHost:process.env.HOST | |“localhost”

或者您可以添加一个策略:

config/policies.js

module.exports.policies = {
  '*': 'isLocal'
}
api/Policys/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'
只需添加以下行:

config/local.js

module.exports.policies = {
  '*': 'isLocal'
}
explicitHost:process.env.HOST | |“localhost”

或者您可以添加一个策略:

config/policies.js

module.exports.policies = {
  '*': 'isLocal'
}
api/Policys/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'
只需添加以下行:

config/local.js

module.exports.policies = {
  '*': 'isLocal'
}
explicitHost:process.env.HOST | |“localhost”

或者您可以添加一个策略:

config/policies.js

module.exports.policies = {
  '*': 'isLocal'
}
api/Policys/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'
只需添加以下行:

config/local.js

module.exports.policies = {
  '*': 'isLocal'
}
explicitHost:process.env.HOST | |“localhost”

或者您可以添加一个策略:

config/policies.js

module.exports.policies = {
  '*': 'isLocal'
}
api/Policys/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'

其想法是nginx处理身份验证和SSL终止,因此nginx应该可以从任何地方访问。我不希望从非本地主机访问节点实例,这样就不能绕过nginx。我的想法是nginx处理身份验证和SSL终止,所以nginx应该可以从任何地方访问。我不希望从非本地主机访问节点实例,这样就不能绕过nginx。我的想法是nginx处理身份验证和SSL终止,所以nginx应该可以从任何地方访问。我不希望从非本地主机访问节点实例,这样就不能绕过nginx。我的想法是nginx处理身份验证和SSL终止,所以nginx应该可以从任何地方访问。我不希望从非本地主机访问节点实例,因此无法绕过nginx。