nodejs,expressjs 服务 PHP 文件 [英] nodejs, expressjs serving PHP files

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

问题描述

好的,我一直在使用 nodejs、expressjs 和 socket.io 来创建一些应用程序.但现在我来到了我想要更进一步的阶段.

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.

我注意到一些节点应用程序在其客户端使用 PHP 进行 twitter 身份验证.当我尝试将我的 client.html 文件重命名为 client.php 并重新启动服务器时,它会抛出一个空白页面

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 /

如何提供 php 文件或者我是否会使用 js 自动执行 twitter ?

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

这是我的 NodeJS server.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");

推荐答案

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

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

  • 在 node 前面有 nginx 并反向代理您要在 node 中处理的所有请求
  • 代理从节点到支持 php 的服务器的 php 请求
  • 对节点中的每个请求产生 php 进程
  • 使用 node fastcgi 协议解析器
  • 制作到 php-fastcgi 的 fastcgi 链接
  • 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天全站免登陆