【问题标题】:hapijs route endpoint issue with reverse proxy apache反向代理apache的hapijs路由端点问题
【发布时间】:2017-05-19 16:41:27
【问题描述】:

我在谷歌云平台上创建了计算引擎实例,并安装了 CentOS 7、apache 和 nodejs。我在服务器上设置了反向代理,这样每当http://[external_ip] 或 domain_name/api/ 在浏览器中点击时,它就会点击 nodejs 服务器。下面是我的反向代理配置

/etc/httpd/conf.d/default-site.com

 ProxyPreserveHost On
 ProxyPass /api/ http://127.0.0.1:8080/
 ProxyPassReverse /api/ http://127.0.0.1:8080/

以上配置运行良好。下面是我的目录结构:

var/www/html/domain_name/public_html/index.html --> 当我们直接在浏览器上点击域名时,它会执行这个文件

var/www/html/domain_name/public/html/api/ --> 这是我的 nodejs 应用程序

我已经安装了 hapi js 框架。我在 /api/ 目录下创建了以下 server.js 文件。

'use strict';

 const Hapi = require('hapi');

 // Create a server with a host and port
 const server = new Hapi.Server();
 server.connection({ 
    host: '127.0.0.1', 
    port: 8080
 });

server.route({
    method: 'GET',
    path:'/', 
    handler: function (request, reply) {    
        return reply('hello world');
    }
});

 // Add the route
server.route({
    method: 'GET',
    path:'/hello', 
    handler: function (request, reply) {    
        return reply('hello world');
    }
});

// Start the server
server.start((err) => {

    if (err) {
        throw err;
    }
    console.log('Server running at:', server.info.uri);
});

我创建了以下两个端点: 1./(当我访问http:///api/时,这条路线是有效的 2./hello(访问http:///api/hello/时这条路由不通

当我们在apache和nodejs中使用反向代理时,是否需要任何其他配置?

【问题讨论】:

    标签: node.js google-cloud-platform reverse-proxy hapijs


    【解决方案1】:

    我想通了。问题在于使用 apache 的反向代理配置。我做了以下更改(从文件夹的 ProxyPass 和 ProxyPassReverse 中删除了斜杠 /)

    ProxyPreserveHost On
    ProxyPass /api http://127.0.0.1:8080/
    ProxyPassReverse /api http://127.0.0.1:8080/
    

    【讨论】:

      猜你喜欢
      • 2013-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-24
      • 2023-04-01
      • 2018-01-05
      • 1970-01-01
      相关资源
      最近更新 更多