使用FastCGI在Nginx后面设置PHP

时间:2014-06-23 11:15:04

标签: nginx fastcgi php

我正在尝试在运行nginx的服务器上设置PHP作为反向代理。我在配置文件中有以下指令:

location ~ \.php(/|$) {
    fastcgi_split_path_info ^(.+?\.php)(/.*)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    include fastcgi_params;
}

在浏览器上打开任何php脚本时,它显示 500内部服务器错误。如果我完全注释掉这个指令,浏览器会抛出一个对话框,提供下载php脚本的选项。可以访问与php脚本位于同一目录中的所有其他文件,如图像文件等。哪里有问题?

编辑:配置文件

upstream the_server {
server localhost:8000;
}

server {
    root    /var/www/linux-dash-master;
    listen  80;
    client_max_body_size    4G;
    keepalive_timeout       5;
    log_format timed_combined '$sent_http_x_username - $remote_addr - [$time_local]  '
    '"$request" $status $body_bytes_sent '
    '"$http_referer" "$http_user_agent" - '
    '$request_time $upstream_response_time $pipe';
    access_log  /var/log/nginx/named.access.log timed_combined;
    error_log  /var/log/nginx/named.error.log debug;
    location /linux-dash-master {
            alias /var/www/linux-dash-master;
            index index.html index.php;
    }
    # Pass PHP requests on to PHP-FPM using sockets
    location ~ /linux-dash-master/.*\.php(/|$) {
            alias /var/www/linux-dash-master;
            #fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_intercept_errors on;
            if ($fastcgi_script_name ~ /linux-dash-master(/.*\.php)$) {
                    set $valid_fastcgi_script_name $1;
            }
            fastcgi_param SCRIPT_FILENAME /var/www/linux-dash-master$valid_fastcgi_script_name;
            #fastcgi_split_path_info ^(.+?\.php)(/.*)$;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            try_files $uri $uri/ /index.php?$args;
            #include fastcgi_params;
      }
      location /static/ {
          alias   /path/to/staticfiles/;
      }
      location / {
          proxy_pass          http://the_server;
          proxy_set_header    Host            $host;
          proxy_set_header    X-Real-IP       $remote_addr;
          proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header    X-Remote-User-Name   $remote_user;
      }

}

1 个答案:

答案 0 :(得分:0)

检查/etc/php5/fpm/pool.d/www.conf是否存在?

如果是这样检查它,请查找以listen开头的行,它是指向文件还是端口?

请注意,以;开头的行不计算