反向代理apache的hapijs路由端点问题
hapijs route endpoint issue with reverse proxy apache
我在Google云平台上创建了计算引擎实例,安装了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 应用程序
我安装了hapijs框架。我在 /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中使用反向代理还需要配置吗?
我想通了。问题出在 apache 的反向代理配置上。我做了以下更改(从文件夹的 ProxyPass 和 ProxyPassReverse 中删除了斜杠 /)
ProxyPreserveHost On
ProxyPass /api http://127.0.0.1:8080/
ProxyPassReverse /api http://127.0.0.1:8080/
我在Google云平台上创建了计算引擎实例,安装了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 应用程序
我安装了hapijs框架。我在 /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中使用反向代理还需要配置吗?
我想通了。问题出在 apache 的反向代理配置上。我做了以下更改(从文件夹的 ProxyPass 和 ProxyPassReverse 中删除了斜杠 /)
ProxyPreserveHost On
ProxyPass /api http://127.0.0.1:8080/
ProxyPassReverse /api http://127.0.0.1:8080/