【问题标题】:Spoof index.php with Node.js route使用 Node.js 路由欺骗 index.php
【发布时间】:2014-02-24 15:47:25
【问题描述】:

我想在 node.js 中重写我的 php 应用程序。我的问题之一是我们有一些用其他语言编写的遗留客户端应用程序直接指向一个 php 文件。是否可以在快速路由中欺骗 php 文件?

我尝试了以下方法:

app.get('/index.php/', function(req, res){
    res.end('test');
});

但是输入 {my domain}/index.php/ 给我

无法获取 /index.php

我想要的是一个名为 legacy.js 的路由文件,然后随着旧版应用程序的更新,我可以一一删除路由。

为任何帮助干杯,

罗宾

【问题讨论】:

    标签: javascript php node.js express


    【解决方案1】:

    几个建议

    建议一

    由于路由定义中的尾部斜杠,您从上面的路由中得到 404。改为:

    app.get('/index.php', function (req, res, next) {
      res.send('PHP route called!');
    });
    

    建议二

    与其尝试让 Node 处理您的 PHP 文件执行,不如将 nginx/apache 设置为节点的反向代理?例如,使用nginx,我们可以同时运行 PHP 脚本和节点后端服务器:

    upstream node {
        server localhost:3000;
    }
    
    server {
        listen 8080;
        server_name localhost;
    
        root /path/to/root/directory;
        index index.php;
    
        # Here we list base paths we would like to direct to PHP with Fast CGI
        location ~* \/tmp|\/blog$ { {
            try_files $uri $uri/ /index.php;
        }
    
        location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
        }
    
        location ~ /\.ht {
            deny all;
        }
    
        # Here we set a reverse proxy to upstream node app for all routes
        # that aren't filtered by the above location directives.
        location / {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_set_header X-NginX-Proxy true;
    
            proxy_pass http://node;
            proxy_redirect off; 
        }
    }
    

    这使您可以在同一个域上同时运行 PHP 和节点,而不必为每个 PHP 脚本执行分叉子进程而头疼——更不用说这会对您的机器产生内存影响了。

    【讨论】:

      猜你喜欢
      • 2021-02-16
      • 2013-08-10
      • 2013-05-03
      • 1970-01-01
      • 2011-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-03
      相关资源
      最近更新 更多