Forum: NGINX which one is better?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Glen L. (Guest)
on 2009-04-21 10:29
(Received via mailing list)
I still wonder which one is better for performance



Pure nginx + php-fpm

Or

Nginx + apache2 + proxy_cache



Anybody knows about this?
Igor S. (Guest)
on 2009-04-21 11:52
(Received via mailing list)
On Tue, Apr 21, 2009 at 01:20:05PM +0700, Glen L. wrote:

> I still wonder which one is better for performance
>
> Pure nginx + php-fpm
>
> Or
>
> Nginx + apache2 + proxy_cache
>
> Anybody knows about this?

Can not say about apache2 vs php-fpm, but you can use fastcgi_cache too.
Glen L. (Guest)
on 2009-04-21 12:19
(Received via mailing list)
Is there any help page regarding fastcgi_cache? Or it's the same format
as
proxy_cache?
Igor S. (Guest)
on 2009-04-21 12:41
(Received via mailing list)
On Tue, Apr 21, 2009 at 03:10:31PM +0700, Glen L. wrote:

> Is there any help page regarding fastcgi_cache? Or it's the same format as
> proxy_cache?

Yes, just s/proxy/fastcgi/.

The single difference is that fastcgi cache requires

      fastcgi_cache_key   localhost:9000$request_uri;

while proxy_cache may use default one, similar to this:

proxy_cache_key  $scheme$proxy_host$uri$is_args$args;
Glen L. (Guest)
on 2009-04-21 12:51
(Received via mailing list)
I already tried this

Here's the config

    fastcgi_cache_path  /data/nginx/cache  levels=1:2 keys_zone=one:10m
inactive=7d  max_size=200m;
    fastcgi_temp_path   /data/nginx/temp;

        location @joomla {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_param  SCRIPT_FILENAME
/home/kompastv/web/index.php;
            fastcgi_cache                   one;
            fastcgi_cache_key               127.0.0.1:9000$request_uri;
            fastcgi_cache_valid             200  1h;

/data/nginx/cache and /data/nginx/temp is still empty

root     28119  0.0  0.0  13940   496 ?        Ss   15:41   0:00 nginx:
master process /etc/nginxnew/sbin/nginx -c /etc/nginx/nginx.conf
nginx     28120  1.3  0.2  17328  4408 ?        R    15:41   0:01 nginx:
worker process
nginx    28122  1.6  0.2  17384  4540 ?        S    15:41   0:01 nginx:
worker process
nginx    28123  0.0  0.0  14096   800 ?        S    15:41   0:00 nginx:
cache manager process

is there somethink i've missed?
Igor S. (Guest)
on 2009-04-21 13:06
(Received via mailing list)
On Tue, Apr 21, 2009 at 03:44:28PM +0700, Glen L. wrote:

>             fastcgi_param  SCRIPT_FILENAME  /home/kompastv/web/index.php;
> nginx    28122  1.6  0.2  17384  4540 ?        S    15:41   0:01 nginx:
> worker process
> nginx    28123  0.0  0.0  14096   800 ?        S    15:41   0:00 nginx:
> cache manager process
>
> is there somethink i've missed?

Does fastcgi return Expires or Cache-Control headers which may forbid
caching ?
Glen L. (Guest)
on 2009-04-21 13:13
(Received via mailing list)
How do i check that? Becase i'm using default configuration
Igor S. (Guest)
on 2009-04-21 14:43
(Received via mailing list)
On Tue, Apr 21, 2009 at 04:02:57PM +0700, Glen L. wrote:

> How do i check that? Becase i'm using default configuration

If you use Firefox:
http://livehttpheaders.mozdev.org

Could you create debug log ?
Glen L. (Guest)
on 2009-04-21 14:58
(Received via mailing list)
Please check http://pastebin.com/d448b8b03

I've uploaded the livehttpheaders
Glen L. (Guest)
on 2009-04-21 15:01
(Received via mailing list)
[root@mp-ws-06 nginx-0.7.52]# tail -f /var/log/nginx/error.log | grep
data
2009/04/21 17:51:21 [debug] 30424#0: cache file:
"/data/nginx/cache/3/06/6fecda1e6dc4d639bbfabfe771b63063"
2009/04/21 17:51:21 [debug] 30424#0: cache file:
"/data/nginx/cache/8/00/7df93c5fa8eb0301382ec66dc9e54008"
2009/04/21 17:51:23 [debug] 30425#0: cache file:
"/data/nginx/cache/5/db/bc8df465ca5a5c053713a34370befdb5"
2009/04/21 17:51:24 [debug] 30424#0: cache file:
"/data/nginx/cache/5/db/bc8df465ca5a5c053713a34370befdb5"
2009/04/21 17:51:24 [debug] 30424#0: cache file:
"/data/nginx/cache/c/94/179da50f035455138b0ac1070c64494c"

[root@mp-ws-06 nginx-0.7.52]# cd /data/nginx/cache/
[root@mp-ws-06 cache]# ls -al
total 8
drwx------ 2 kompastv root 4096 Apr 21 15:36 .
drwxr-xr-x 4 root     root 4096 Apr 21 15:36 ..
Igor S. (Guest)
on 2009-04-21 15:10
(Received via mailing list)
On Tue, Apr 21, 2009 at 05:49:24PM +0700, Glen L. wrote:

> Please check http://pastebin.com/d448b8b03
>
> I've uploaded the livehttpheaders

At least

http://www.kompas-tv.com/modules/mod_smo_ajax_shou...

should be cacheable. Probably it is handled by not @joomla, but by
something like location ~ "\.php$".
Igor S. (Guest)
on 2009-04-21 15:11
(Received via mailing list)
On Tue, Apr 21, 2009 at 05:51:57PM +0700, Glen L. wrote:

> "/data/nginx/cache/c/94/179da50f035455138b0ac1070c64494c"
>
> [root@mp-ws-06 nginx-0.7.52]# cd /data/nginx/cache/
> [root@mp-ws-06 cache]# ls -al
> total 8
> drwx------ 2 kompastv root 4096 Apr 21 15:36 .
> drwxr-xr-x 4 root     root 4096 Apr 21 15:36 ..

Could you run

egrep 'cacheable|error|crit' /var/log/nginx/error.log

?
Glen L. (Guest)
on 2009-04-21 15:51
(Received via mailing list)
location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_param  SCRIPT_FILENAME
/home/myhome/web$fastcgi_script_name;
            fastcgi_index  index.php;
            fastcgi_cache                   one;
            fastcgi_cache_key               127.0.0.1:9000$request_uri;
            fastcgi_cache_valid             200  1h;
            include /etc/nginx/fastcgi_params;
        }

It seems that the /data/nginx/cache directory now have some files :D

So that the location which is go to @joomla will be cached aswell?
Glen L. (Guest)
on 2009-04-21 15:51
(Received via mailing list)
Igor S. (Guest)
on 2009-04-21 16:01
(Received via mailing list)
On Tue, Apr 21, 2009 at 06:41:31PM +0700, Glen L. wrote:

>
> It seems that the /data/nginx/cache directory now have some files :D
>
> So that the location which is go to @joomla will be cached aswell?

Yes.
Igor S. (Guest)
on 2009-04-21 16:01
(Received via mailing list)
On Tue, Apr 21, 2009 at 06:41:31PM +0700, Glen L. wrote:

>
> It seems that the /data/nginx/cache directory now have some files :D

BTW, it will be cached till Expires header.
Jonathan V. (Guest)
on 2009-04-21 22:56
(Received via mailing list)
This command serves the right directories, and pipes them through php:

    location /careers) {
        root /home/artwelove/_current/web/www.artwelove.com-news/news;
  include  /usr/local/nginx/_macros/php.conf;
        index index.php index.html;
    }


This command serves the right directories, but does not pipe them
through php:

    location ~ /careers {
        root /home/artwelove/_current/web/www.artwelove.com-news/news;
  include  /usr/local/nginx/_macros/php.conf;
        index index.php index.html;
    }


I can't figure this one out...  This is a simplified example, but just
changing the location to a regex kills the php ability

Anyone have a clue ?

Oh, and this is on nginx 0.6.34:


// Jonathan V.

e. removed_email_address@domain.invalid
w. http://findmeon.com/user/jvanasco
blog. http://destructuring.net

|   -   -   -   -   -   -   -   -   -   -
|   Founder/CEO - FindMeOn, Inc.
|      FindMeOn.com - The cure for Multiple Web Personality Disorder
|   -   -   -   -   -   -   -   -   -   -
|   CTO - ArtWeLove, LLC
|      ArtWeLove.com - Explore Art On Your Own Terms
|   -   -   -   -   -   -   -   -   -   -
|   Founder - SyndiClick
|      RoadSound.com - Tools for Bands, Stuff for Fans
|   -   -   -   -   -   -   -   -   -   -
Igor S. (Guest)
on 2009-04-22 00:42
(Received via mailing list)
On Tue, Apr 21, 2009 at 02:49:33PM -0400, Jonathan V. wrote:

> through php:
>
> Anyone have a clue ?
>
> Oh, and this is on nginx 0.6.34:

Build nginx with debug log, then grep the lines:

test location: "...."
test location: "...."
test location: "...."
test location: "...."
using configuration "....."
Jonathan V. (Guest)
on 2009-04-22 02:42
(Received via mailing list)
On Apr 21, 2009, at 4:31 PM, Igor S. wrote:

> Build nginx with debug log, then grep the lines:
>
> test location: "...."
> test location: "...."
> test location: "...."
> test location: "...."
> using configuration "....."



i get the text below ; it makes no sense to me while PHP gets ignored
from this.


2009/04/21 22:31:55 [debug] 20025#0: *48 using configuration "^/(rsvp|
pages|careers)/"
2009/04/21 22:31:55 [debug] 20025#0: *48 http cl:-1 max:1048576
2009/04/21 22:31:55 [debug] 20025#0: *48 generic phase: 3
2009/04/21 22:31:55 [debug] 20025#0: *48 http script value: "/home/
artwelove/_current/web/www.artwelove.com-downtime/-news"
2009/04/21 22:31:55 [debug] 20025#0: *48 http script file op
0000000000000000 "/home/artwelove/_current/web/www.artwelove.com-
downtime/-news"
2009/04/21 22:31:55 [debug] 20025#0: *48 add cleanup: 00000000006A7DA8
2009/04/21 22:31:55 [debug] 20025#0: *48 http script file op false
2009/04/21 22:31:55 [debug] 20025#0: *48 http script if
2009/04/21 22:31:55 [debug] 20025#0: *48 http script if: false
2009/04/21 22:31:55 [debug] 20025#0: *48 post rewrite phase: 4
2009/04/21 22:31:55 [debug] 20025#0: *48 generic phase: 5
2009/04/21 22:31:55 [debug] 20025#0: *48 generic phase: 6
2009/04/21 22:31:55 [debug] 20025#0: *48 access phase: 7
2009/04/21 22:31:55 [debug] 20025#0: *48 access phase: 8
2009/04/21 22:31:55 [debug] 20025#0: *48 post access phase: 9
2009/04/21 22:31:55 [debug] 20025#0: *48 content phase: 10
2009/04/21 22:31:55 [debug] 20025#0: *48 content phase: 11
2009/04/21 22:31:55 [debug] 20025#0: *48 content phase: 12
2009/04/21 22:31:55 [debug] 20025#0: *48 http filename: "/home/
artwelove/_current/web/www.artwelove.com-news/news/careers/intern-
technology-developer/index.php"
2009/04/21 22:31:55 [debug] 20025#0: *48 add cleanup: 00000000006A7E40
2009/04/21 22:31:55 [debug] 20025#0: *48 http static fd: 6
2009/04/21 22:31:55 [debug] 20025#0: *48 http set discard body
2009/04/21 22:31:55 [debug] 20025#0: *48 HTTP/1.1 200 OK
Server: nginx/0.6.36
Date: Tue, 21 Apr 2009 22:31:55 GMT
Content-Type: application/octet-stream
Content-Length: 15954
Last-Modified: Tue, 21 Apr 2009 19:20:50 GMT
Connection: keep-alive
Accept-Ranges: bytes


2009/04/21 22:31:55 [debug] 20025#0: *48 write new buf t:1 f:0
00000000006A7FD8, pos 00000000006A7FD8, size: 233 file: 0, size: 0
2009/04/21 22:31:55 [debug] 20025#0: *48 http write filter: l:0 f:0 s:
233
2009/04/21 22:31:55 [debug] 20025#0: *48 http output filter "/careers/
intern-technology-developer/index.php?"
2009/04/21 22:31:55 [debug] 20025#0: *48 copy filter: "/careers/intern-
technology-developer/index.php?"
2009/04/21 22:31:55 [debug] 20025#0: *48 malloc: 000000000069B780:4096
2009/04/21 22:31:55 [debug] 20025#0: *48 http postpone filter "/
careers/intern-technology-developer/index.php?" 00007FFF259EEA00
2009/04/21 22:31:55 [debug] 20025#0: *48 http postpone filter out "/
careers/intern-technology-developer/index.php?"
2009/04/21 22:31:55 [debug] 20025#0: *48 write old buf t:1 f:0
00000000006A7FD8, pos 00000000006A7FD8, size: 233 file: 0, size: 0
2009/04/21 22:31:55 [debug] 20025#0: *48 write new buf t:0 f:1
0000000000000000, pos 0000000000000000, size: 0 file: 0, size: 15954
2009/04/21 22:31:55 [debug] 20025#0: *48 http write filter: l:1 f:0 s:
16187
2009/04/21 22:31:55 [debug] 20025#0: *48 http write filter limit 0
2009/04/21 22:31:55 [debug] 20025#0: *48 writev: 233
2009/04/21 22:31:55 [debug] 20025#0: *48 sendfile: @0 15954
2009/04/21 22:31:55 [debug] 20025#0: *48 sendfile: 15954, @0 15954:15954
2009/04/21 22:31:55 [debug] 20025#0: *48 http write filter
0000000000000000
2009/04/21 22:31:55 [debug] 20025#0: *48 copy filter: 0 "/careers/
intern-technology-developer/index.php?"
2009/04/21 22:31:55 [debug] 20025#0: *48 http finalize request: 0, "/
careers/intern-technology-developer/index.php?"
2009/04/21 22:31:55 [debug] 20025#0: *48 set http keepalive handler
2009/04/21 22:31:55 [debug] 20025#0: *48 http close request
2009/04/21 22:31:55 [debug] 20025#0: *48 http log handler
2009/04/21 22:31:55 [debug] 20025#0: *48 run cleanup: 00000000006A7E40
2009/04/21 22:31:55 [debug] 20025#0: *48 file cleanup: fd:6
2009/04/21 22:31:55 [debug] 20025#0: *48 free: 00000000006A7100,
unused: 16
2009/04/21 22:31:55 [debug] 20025#0: *48 free: 000000000069B780,
unused: 3704
2009/04/21 22:31:55 [debug] 20025#0: *48 event timer add: 3:
65000:1240353180219
2009/04/21 22:31:55 [debug] 20025#0: *48 free: 0000000000708FF0
2009/04/21 22:31:55 [debug] 20025#0: *48 free: 00000000007368C0
2009/04/21 22:31:55 [debug] 20025#0: *48 hc free: 0000000000000000 0
2009/04/21 22:31:55 [debug] 20025#0: *48 hc busy: 0000000000000000 0
2009/04/21 22:31:55 [debug] 20025#0: *48 tcp_nodelay
2009/04/21 22:31:55 [debug] 20025#0: *48 post event 00000000006D24F0
2009/04/21 22:31:55 [debug] 20025#0: *48 delete posted event
00000000006D24F0
2009/04/21 22:31:55 [debug] 20025#0: *48 http keepalive handler
2009/04/21 22:31:55 [debug] 20025#0: *48 malloc: 0000000000708FF0:1024
2009/04/21 22:31:55 [debug] 20025#0: *48 recv: fd:3 -1 of 1024
2009/04/21 22:31:55 [debug] 20025#0: *48 recv() not ready (11:
Resource temporarily unavailable)
2009/04/21 22:31:55 [debug] 20025#0: *48 http keepalive handler
2009/04/21 22:31:55 [debug] 20025#0: *48 recv: fd:3 0 of 1024
2009/04/21 22:31:55 [info] 20025#0: *48 client 64.0.35.34 closed
keepalive connection
2009/04/21 22:31:55 [debug] 20025#0: *48 close http connection: 3
2009/04/21 22:31:55 [debug] 20025#0: *48 event timer del: 3:
1240353180219
2009/04/21 22:31:55 [debug] 20025#0: *48 free: 0000000000708FF0
2009/04/21 22:31:55 [debug] 20025#0: *48 free: 0000000000000000
2009/04/21 22:31:55 [debug] 20025#0: *48 free: 0000000000000000
2009/04/21 22:31:55 [debug] 20025#0: *48 free: 000000000069ADF0,
unused: 8
2009/04/21 22:31:55 [debug] 20025#0: *48 free: 00000000007094D0,
unused: 96



// Jonathan V.

e. removed_email_address@domain.invalid
w. http://findmeon.com/user/jvanasco
blog. http://destructuring.net

|   -   -   -   -   -   -   -   -   -   -
|   Founder/CEO - FindMeOn, Inc.
|      FindMeOn.com - The cure for Multiple Web Personality Disorder
|   -   -   -   -   -   -   -   -   -   -
|   CTO - ArtWeLove, LLC
|      ArtWeLove.com - Explore Art On Your Own Terms
|   -   -   -   -   -   -   -   -   -   -
|   Founder - SyndiClick
|      RoadSound.com - Tools for Bands, Stuff for Fans
|   -   -   -   -   -   -   -   -   -   -
Jb j. (Guest)
on 2009-04-22 02:51
nginx + php-fpm have worked nicely for the sites I've set up.

YMMV.

Glen L. wrote:
> I still wonder which one is better for performance
>
>
>
> Pure nginx + php-fpm
>
> Or
>
> Nginx + apache2 + proxy_cache
>
>
>
> Anybody knows about this?
Michael S. (Guest)
on 2009-04-22 03:06
(Received via mailing list)
you forgot to include what your php.conf or whatever it was says
AMP Admin (Guest)
on 2009-04-22 03:19
(Received via mailing list)
nginx + php-fpm + xCache... so far I'm loving it.
Jonathan V. (Guest)
on 2009-04-22 09:47
(Received via mailing list)
On Apr 21, 2009, at 6:59 PM, Michael S. wrote:

> you forgot to include what your php.conf or whatever it was says


michael-

the problem is that PHP isn't invoked with this regex location

as per the original posting, the script pipes to php if we have

  location /careers

but if we have
  location ~ /careers

its served without php




// Jonathan V.

e. removed_email_address@domain.invalid
w. http://findmeon.com/user/jvanasco
blog. http://destructuring.net

|   -   -   -   -   -   -   -   -   -   -
|   Founder/CEO - FindMeOn, Inc.
|      FindMeOn.com - The cure for Multiple Web Personality Disorder
|   -   -   -   -   -   -   -   -   -   -
|   CTO - ArtWeLove, LLC
|      ArtWeLove.com - Explore Art On Your Own Terms
|   -   -   -   -   -   -   -   -   -   -
|   Founder - SyndiClick
|      RoadSound.com - Tools for Bands, Stuff for Fans
|   -   -   -   -   -   -   -   -   -   -
Michael S. (Guest)
on 2009-04-22 09:57
(Received via mailing list)
i think knowing that is in that conf may be relevant.
Igor S. (Guest)
on 2009-04-22 10:54
(Received via mailing list)
On Tue, Apr 21, 2009 at 06:38:13PM -0400, Jonathan V. wrote:

>
> i get the text below ; it makes no sense to me while PHP gets ignored
> from this.
>
>
> 2009/04/21 22:31:55 [debug] 20025#0: *48 using configuration "^/(rsvp|
> pages|careers)/"

nginx matches

     location ~ "^/(rsvp|pages|careers)/" {

> 2009/04/21 22:31:55 [debug] 20025#0: *48 http script value: "/home/
> artwelove/_current/web/www.artwelove.com-downtime/-news"
> 2009/04/21 22:31:55 [debug] 20025#0: *48 http script file op
> 0000000000000000 "/home/artwelove/_current/web/www.artwelove.com-
> downtime/-news"

     here is testing existence of file
         /home/artwelove/_current/web/www.artwelove.com-downtime/-news"

> 2009/04/21 22:31:55 [debug] 20025#0: *48 add cleanup: 00000000006A7DA8
> 2009/04/21 22:31:55 [debug] 20025#0: *48 http script file op false
> 2009/04/21 22:31:55 [debug] 20025#0: *48 http script if
> 2009/04/21 22:31:55 [debug] 20025#0: *48 http script if: false
> 2009/04/21 22:31:55 [debug] 20025#0: *48 post rewrite phase: 4

     it does not exists, so the static file is handled:

> 2009/04/21 22:31:55 [debug] 20025#0: *48 http filename: "/home/
> artwelove/_current/web/www.artwelove.com-news/news/careers/intern-
> technology-developer/index.php"

Could you show

location ~ "^/(rsvp|pages|careers)/" ?
Jonathan V. (Guest)
on 2009-04-22 18:46
(Received via mailing list)
On Apr 22, 2009, at 2:42 AM, Igor S. wrote:
> location ~ "^/(rsvp|pages|careers)/" ?

in it's entirety:

     location ~ ^/(rsvp|pages|careers)/ {
         if ( -f /home/artwelove/_current/web/www.artwelove.com-
downtime/-news ) {
             return 503;
         }
         root  /home/artwelove/_current/web/www.artwelove.com-news/news;
         include  /usr/local/nginx/_macros/php.conf;
         index  index.php index.html;
     }

the if block was a trick i learned off this list to handle downtime
with semaphores

this block works perfectly as an exact match... and these locations
are just shotcuts to remove a few nested dirs off of a /news main
location.  reaching this through /news/careers works as intended ;
rewriting this block to be location /careers works as intended.
Jonathan V. (Guest)
on 2009-04-22 23:32
(Received via mailing list)
On Apr 22, 2009, at 2:42 AM, Igor S. wrote:
> location ~ "^/(rsvp|pages|careers)/" ?

in it's entirety:

    location ~ ^/(rsvp|pages|careers)/ {
        if ( -f /home/artwelove/_current/web/www.artwelove.com-
downtime/-news ) {
            return 503;
        }
        root  /home/artwelove/_current/web/www.artwelove.com-news/news;
        include  /usr/local/nginx/_macros/php.conf;
        index  index.php index.html;
    }

the if block was a trick i learned off this list to handle downtime
with semaphores

this block works perfectly as an exact match... and these locations
are just shotcuts to remove a few nested dirs off of a /news main
location.  reaching this through /news/careers works as intended ;
rewriting this block to be location /careers works as intended.

( resent as my mac crashed during sending, and this didn't seem to hit
the list or sent-box.  apologies if this is a duplicate )
Jonathan V. (Guest)
on 2009-04-23 21:59
(Received via mailing list)
I figured out the problem, and a temporary solution

looking through my mailbox i saw this thread:

  From:   removed_email_address@domain.invalid
  Subject:   php and locations with regex (round 2)
  Date:   October 23, 2007 6:44:21 AM EDT

which was the same issue as me.

the problem is that my macro for php is the very standard block

  location ~ *.php {}

which should not have been used within a static or regex location -
only in a server
but there is a behavior where it does work on static location

so i created a temporary fix: i made another macro which was just the
contents of the php block

in the 2007 thread, igor said that it would be bad to use an if ()
match on files... is this still true?

ideally i would like to do this:

location ~ /regex/ {
  if ( filename *~ *.php(\?.*)? ) {
    fcgi passover
  }
  handle static stuff here
}
This topic is locked and can not be replied to.