nodejs,expressjs提供PHP文件 [英] nodejs, expressjs serving PHP files

查看:201
本文介绍了nodejs,expressjs提供PHP文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我一直在玩nodejs,expressjs和socket.io来创建一些应用程序。但现在我来到了我想要进一步的事情的舞台。



我已经注意到在客户端使用PHP的twitter认证的几个节点应用程序。当我尝试将client.html文件重命名为client.php并重新启动服务器时,会使用

 不能GET / 

如何提供php文件,或者我会使用js自动使用Twitter?



这是我的NodeJS server.js

  var http = require('http '),
express = require('express');

var app = module.exports = express.createServer();

//配置
app.configure(function(){
app.use(express.static(__ dirname +'/ public'));
}) ;

app.listen(1234);
console.log(server start on port:1234);


解决方案

如前所述,node.js本身不会为您解释php文件。可用的选项是:




  • 在节点和反向代理之前都有nginx所有要从节点中处理的请求

  • 代理php请求从节点到支持php的服务器

  • 在节点
  • 中的每个请求的spawn php进程
  • make fastcgi link php-fastcgi使用节点fastcgi协议解析器


Ok I've been playing around with nodejs, expressjs and socket.io to create some applications. But now im coming to the stage where i want to take things a bit further.

I have noticed a few node apps using PHP for twitter auth on their client side. When I attempt to rename my client.html file to client.php and restart the server it throws up a blank page with this

Cannot GET /

How do would serve php files or would i do twitter auto using js?

This is my NodeJS server.js

var http = require('http'),  
    express = require('express');

var app = module.exports = express.createServer();

// Configuration
app.configure(function(){
    app.use(express.static(__dirname + '/public'));
});

app.listen(1234);
console.log("server started on port :1234");

解决方案

As already noted, node.js itself won't interpret php files for you. Available options are:

  • have nginx in front of node and reverse proxy all request you want to process in node from it
  • proxy php requests from node to php-capable server
  • spawn php process on each request in node
  • make fastcgi link to php-fastcgi using node fastcgi protocol parser

这篇关于nodejs,expressjs提供PHP文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆