通过网址

时间:2015-12-11 05:40:54

标签: php nginx

我有一个php脚本hook.php,位于/var/utils,内容是打印

<?php
echo "To be print.";

我的nginx配置就是这个。

server {
  listen 8322;
  server_name docs.com;

  location /hook.php {
    root `/var/utils`;
    fastcgi_pass 127.0.0.1:9000;
    include fastcgi_params;
  }
}

当我尝试在浏览器中使用docs.com:8322/hook.php执行它时,它不会打印任何内容。当我尝试通过cli $ php hook.php执行它时,它会打印一些东西。 Net stat显示我的php-fpm正在端口9000中运行

我在这里缺少什么?

谢谢!

更新

解决方案是在nginx配置中添加fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

server {
  listen 8322;
  server_name docs.com;

  location /hook.php {
    root `/var/utils`;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass 127.0.0.1:9000;
    include fastcgi_params;
  }
}

[CLOSED]

2 个答案:

答案 0 :(得分:0)

你可以试试这个:

sitename.com/script.php?f=your_function_name

在您的script.php文件中;

if(function_exists($_GET['f'])) {
  $_GET['f']();
}

答案 1 :(得分:0)

解决方案太过添加fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;在nginx配置

server {
  listen 8322;
  server_name docs.com;

  location /hook.php {
    root `/var/utils`;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass 127.0.0.1:9000;
    include fastcgi_params;
  }
}