nodejs, expressjs serving PHP files

假装没事ソ 提交于 2019-12-30 06:42:14

问题


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");

回答1:


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



回答2:


Uh, skip PHP entirely and integrate everyauth into your app.




回答3:


PHP-EXPRESS should do. Just install the package and follow the docs.

https://www.npmjs.com/package/php-express



来源:https://stackoverflow.com/questions/6836842/nodejs-expressjs-serving-php-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!