Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在nginx配置下执行php脚本_Php_Nginx - Fatal编程技术网

在nginx配置下执行php脚本

在nginx配置下执行php脚本,php,nginx,Php,Nginx,我在其配置中有以下nginx服务器块 server { listen 80; server_name mydomain.com; location /deploy { alias /home/somedir/deploy/; } # pass the PHP scripts to FastCGI server listening on /var/run/php5-fpm.sock location ~ \.ph

我在其配置中有以下nginx服务器块

server {
    listen       80;
    server_name mydomain.com;
    location /deploy {
        alias /home/somedir/deploy/;
        }

    # pass the PHP scripts to FastCGI server listening on /var/run/php5-fpm.sock
    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;

    }
  }
我想在url mydomain.com/deploy/erp/index.php或mydomain.com/deploy/erp上执行一个php文件


上面的内容是下载php文件,而不是执行它。我在谷歌上搜索并找到了一些解决方案,要求您定义一个www目录或其他什么。我只需要在特定url的特定目录中执行该文件。我的选择是什么?

您还没有告诉nginx如何处理.php文件。假设您使用的是php fpm,您将需要以下内容:

server {
  listen       80;
  server_name mydomain.com;

  root /home/somedir;

  location / {
    try_files $uri $uri/ =404;
  }

  location /deploy {
    try_files $uri $uri/ /index.php?$args;
  }

  location ~ \.php$ {
    try_files $uri =404;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass 127.0.0.1:9000;
    include fastcgi_params;
  }
}

查看我的编辑。。。不起作用。我现在得到一个404!它可以工作,但有一点变化。你的代码实际上可以在UbuntuVerions 12.xx及以下版本上运行。在上面,您需要传递unix:/var/run/php5-fpm.sock而不是127.0.0.1:90000太棒了!这取决于您的fpm设置(例如/etc/php/fpm/php fpm.conf)——您可以选择TCP或unix套接字(请参阅:)