使用express.js和apache

时间:2017-12-06 10:30:27

标签: node.js apache express proxy http-proxy

我想从apache安装php页面。这只能由NodeJS访问,因为身份验证是从nodejs端实现的。 所以我必须在访问php页面之前创建一个代理HTT(它没有实现安全性)。

这是我的虚拟主机apache:

# Virtual Hosts
#
<VirtualHost *:1882>
  ServerName localhost
  ServerAlias localhost
  DocumentRoot "${INSTALL_DIR}/www"

  <Directory "${INSTALL_DIR}/www/">
    Options +Indexes +Includes +FollowSymLinks +MultiViews
    AllowOverride All
    Require local
  </Directory>

  <Location />
    Order deny,allow
    Allow from localhost
  </Location>

</VirtualHost>

<VirtualHost *:1882>
    ServerName ***
    ServerAlias ApplicationServer
    ProxyRequests Off

    ErrorLog "${INSTALL_DIR}/logs/app_error.log"
  CustomLog "${INSTALL_DIR}/logs/app_access.log" combined

    <Location />
    ProxyPass http://localhost:3000/ retry=0
    ProxyPassReverse http://localhost:3000/
    Order deny,allow
    Allow from all
  </Location>
</VirtualHost>

所以架构就像:

Virtualhost2 apache(用于HTTPS) - &gt; nodejs应用程序(用于服务多个事物以及安全连接和会话) - &gt; virtualhost1 apache(用于提供php文件)。

以下是使用nodejs的代理HTTP的代码:

// proxy.js
var router = require('express').Router();
const request = require('request');

router.get('/', function (req, res) {
    // correct URL
    var proxy = request(req.url);
    req.pipe(proxy);
    proxy.pipe(res)
})

module.exports = function (auth_fn) {
    if (auth_fn !== undefined) router.use(auth_fn);
    return router;
}

//index.js

...
const auth = require("./auth.js")(app);
var proxy = require("./router/proxy.js")(auth.authenticate);
app.use("/locales", proxy)
app.listen(port, function () {
    console.log(`Example app listening on port ${port}`);
})
...

我想从“/ locales /”

访问我的PHP页面

从现在开始,当访问localhost:3000 / locales / index.php时,没有任何反应,并且不会触发代理功能。

编辑:

这是apache输出,代理请求旁边:

127.0.0.1 - - [06/Dec/2017:11:45:59 +0100] "-" 408 -
127.0.0.1 - - [06/Dec/2017:11:45:59 +0100] "-" 408 -
127.0.0.1 - - [06/Dec/2017:11:45:59 +0100] "-" 408 -
127.0.0.1 - - [06/Dec/2017:11:45:59 +0100] "-" 408 -
127.0.0.1 - - [06/Dec/2017:11:45:59 +0100] "-" 408 -

请注意,当我使用direct url

从localhost调用页面时,一切正常

0 个答案:

没有答案