dtmu88600 2014-06-23 11:15
浏览 67

使用FastCGI在Nginx后面设置PHP

I am trying to set up PHP on my server running nginx as reverse proxy. I have the following directive in the configuration file:

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

On opening any php script on the browser it says 500 Internal server error. If I completely comment out this directive, the browser throws a dialog box giving an option to download the php script. All other files like image files etc. in the same directory as the php scripts are accessible. Where can there be a problem?

EDIT: The configuration file

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条回答 默认 最新

  • drl959975 2014-06-23 12:05
    关注

    Check /etc/php5/fpm/pool.d/www.conf does it exist?

    If so check inside it, look for a line that starts with listen, does it point for a file or a port ?

    Note that lines starting with ; don't count

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条