apache / incubator-pagespeed-ngx

Automatic PageSpeed optimization module for Nginx
http://ngxpagespeed.com/
Apache License 2.0
4.37k stars 364 forks source link

nginx + pagespeed + php-fpm doesn't work after second request #286

Closed frutik closed 11 years ago

frutik commented 11 years ago

Hi guys.

I have strange issue when trying to setup pagespeed

stock nginx + stock php-fpm works as expected nginx built from source (without pagespeed) + stock php-fpm works as expected nginx built from source with pagespeed + stock php-fpm - first 2 requests works as expected, after that all next responses contains full php source (instead of html) until restart of nginx

root@dev:/usr/local/nginx/conf# lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 12.10 Release: 12.10 Codename: quantal

nginx-1.4.0.tar.gz release-1.5.27.1-beta.zip stock php-fpm

http { include /usr/local/nginx/conf/mime.types; default_type application/octet-stream;

root           /usr/local/nginx/html;

sendfile        on;
keepalive_timeout  65;

server {
    listen       80;
pagespeed off;

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

    location ~ \.php$ {
        fastcgi_pass   unix:/var/run/php5-fpm.sock;
        fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        /usr/local/nginx/conf/fastcgi_params;
    }
}
jeffkaufman commented 11 years ago

Yikes; that shouldn't happen. Quickly testing now with php-cgi I'm not seeing this:

php-cgi -b 127.0.0.1:9000

location ~ \.php$ {
  fastcgi_param SCRIPT_FILENAME $request_filename;
  fastcgi_param QUERY_STRING $query_string;
  fastcgi_param REQUEST_METHOD $request_method;
  fastcgi_param CONTENT_TYPE $content_type;
  fastcgi_param CONTENT_LENGTH $content_length;
  fastcgi_pass 127.0.0.1:9000;
}

curl localhost:8050/mod_pagespeed_test/php_withoutflush.php
curl localhost:8050/mod_pagespeed_test/php_withoutflush.php
curl localhost:8050/mod_pagespeed_test/php_withoutflush.php
curl localhost:8050/mod_pagespeed_test/php_withoutflush.php
curl localhost:8050/mod_pagespeed_test/php_withoutflush.php

I'm going to try to reproduce your setup fully to figure out what's going on.

jeffkaufman commented 11 years ago

I set up a test [1] that's much closer to your setup: I copied your config, used php5-fpm on a unix socket, but I'm still not seeing this.

When you restarted nginx, this happened again?

[1] https://github.com/pagespeed/ngx_pagespeed/tree/jefftk-test-php-more

frutik commented 11 years ago

Hi, Jeff.

Do you need any additional configs etc? Perhaps I can try to debug something on my own to help you?

frutik commented 11 years ago

yes. every time after restart of nginx it serves successfully only two first requests after that sends source of php file

frutik commented 11 years ago

I'll try to make screencast

jeffkaufman commented 11 years ago

Is there anything in the error log? Is there anything unusual about the php url in question?

jeffkaufman commented 11 years ago

(You might need to set your error log to "debug" in order to see relevant errors.)

jeffkaufman commented 11 years ago

If I'm reading it right it's printing:

<?php
    phpinfo();
>

This is the content of index.php on your system?

frutik commented 11 years ago

yep. nothing interesting in logs, btw

jeffkaufman commented 11 years ago

Trying to reproduce this more, still failing.

Here's the nginx.conf I'm using:

worker_processes  1;

events {
  worker_connections  1024;
}

error_log /home/jefftk/php-error.log;

http {
  access_log /home/jefftk/php-access.log;

  include /home/jefftk/mime.types;
  default_type application/octet-stream;

  root /home/jefftk/nginx/html;

  sendfile        on;
  keepalive_timeout  65;

  server {
    listen       8090;
    pagespeed off;

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

    location ~ \.php$ {
      fastcgi_pass   unix:/var/run/php5-fpm.sock;
      fastcgi_index  index.php;
      fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
      include /home/jefftk/fastcgi_params;
    }
  }
}

My fastcgi params are the 1.4.0 default:

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  HTTPS              $https if_not_empty;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

My index.php is:

<?php
    phpinfo();
?>

Running:

curl localhost:8090/index.php

repeatedly I just get the output of phpinfo().

jeffkaufman commented 11 years ago

Remaining differences between our setups:

Is there anything you're including in your ./configure that I wouldn't be?

frutik commented 11 years ago

Sorry, I'll be back in a few hours

eleshar commented 11 years ago

I'm experiencing the same issue on the 1.5.27.1-beta release, if I switch to the alpha-r2338 branch it works.

oschaaf commented 11 years ago

I tried to reproduce, but failed using nginx1.4.0 on ubuntu12.04.2 (x86_64). Both debug and release configured with either pagespeed on; and pagespeed off; don't reproduce this for me. The try_files statement doesn't work for me, but if I remove $uri/ it does. The try_files path also does not reproduce the problem for me either.

frutik commented 11 years ago

I am trying to create vagrant/puppet stuff to have reproducible environment which could help reproduce issue

jeffkaufman commented 11 years ago

if I switch to the alpha-r2338 branch it works

Did you try any of the others? In particular, alpha-2618 or alpha-2748? That would be helpful for trying to narrow down when this started.

eleshar commented 11 years ago

I only checked that one since i recall it was working.

I've tested with alpha-2618 and alpha-2748 both working for me.

jeffkaufman commented 11 years ago

@eleshar thanks for checking them!

alpha-2748 wasn't very long ago. The only two significant changes I see since then are:

jeffkaufman commented 11 years ago

@frutik

vagrant/puppet stuff to have reproducible environment

That would be great.

jeffkaufman commented 11 years ago

For now people should use alpha-2748 (and the install instructions say to). Master is updated to fix this, and 1.5.27.2 which I'm trying to get out soon will have this fixed.