nodejs,expressjs提供PHP文件 [英] nodejs, expressjs serving PHP files
问题描述
我已经注意到在客户端使用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屋!