【发布时间】:2017-01-10 13:38:30
【问题描述】:
我正在开发一个网站内容基于 Apache 服务器后面的 PHP(CodeIgniter) 的项目,我的职责是编写一个 node.js 作为 API 用于即将推出的移动版应用程序。 (注意,我们的托管是托管的,我们无法访问虚拟主机,因此无法使用 proxypass)
我必须让我的节点文件在 Apache 后面运行,在一个像“域名/api”这样的 URL 中。 当调用上述 URL 时,Apache 必须将此请求桥接到节点所在的 localhost:port。
这是我的 node.js 文件:
var fs = require('fs');
var http = require('http');
var app = require('express')();
var options = {
};
app.get('/', function (req, res) {
res.send('Hello World!');
});
http.createServer( app).listen(61000, function () {
console.log('Started!');
});
这是我的 .htaccess 文件:
RewriteEngine on
RewriteRule ^$ /index.php [L]
RewriteCond %{HTTP_HOST} !^ourdomainname\.com
RewriteRule (.*) http://ourdomainname.com/$1 [R=301,L]
RewriteCond $1 !^(index\.php|info.php|resource|system|user_guide|bootstrap|robots\.txt|favicon\.ico|google<somevalues>.html)
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteRule ^/api$ http://127.0.0.1:61000/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/api/(.*)$ http://127.0.0.1:61000/$1 [P,L]
虽然节点在本地工作(在我们的托管托管服务器上)(我可以调用“lynx localhost:61000/”并查看正确的输出),但它不能在本地外部工作。我们对“ourdomainname.com:61000/api”的所有调用都发送到 CodeIgniter(PHP),而不是我们的 node.js 文件。
感谢任何帮助。
【问题讨论】:
标签: node.js apache .htaccess proxy behind