php5-cgi给清漆502,但没有

问题总结:

php5-fastcgi与nginx协同工作,但不支持nginx + varnish(502 Bad Gateway)

有没有人有什么我可以改变清漆工作的build议?

问题细节:

这是我的configuration:

(听80)nginx(请求8181)==>(听8181)varnish ==>(听9090)php5-fastcgi

/etc/nginx/conf.d/mydomain.com

server { listen 80; server_name mydomain.com; index index.html index.htm index.php; keepalive_timeout 30; root /var/www/assets; location = /favicon.ico { log_not_found off; access_log off; } location ~\.php$ { root /var/www/api; add_header Access-Control-Allow-Origin *; fastcgi_pass 127.0.0.1:8181; include fastcgi_params; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } location ~ ^/(api|wp) { root /var/www/api; try_files $uri $uri/ /index.php?q=$uri&$args; } } 

在/ etc /默认/清漆

 START=yes NFILES=131072 MEMLOCK=82000 DAEMON_OPTS="-a :8181 \ -T localhost:6082 \ -f /etc/varnish/default.vcl \ -S /etc/varnish/secret \ -s malloc,256M" 

/etc/varnish/default.vlc

 backend default { .host = "127.0.0.1"; .port = "9090"; } sub vcl_recv { set req.backend = default; if (!(req.url ~ "wp-(login|admin)")) { unset req.http.cookie; } return(lookup); } sub vcl_miss { return(fetch); } sub vcl_hit { return(deliver); } sub vcl_fetch { if (!(req.url ~ "wp-(login|admin)")) { unset beresp.http.set-cookie; } set beresp.ttl = 24h; set beresp.http.X-Cacheable = "YES"; unset beresp.http.Vary; return(deliver); } sub vcl_deliver { return(deliver); } 

的/ usr /斌/ PHP5-fastcgi的-对

 #!/bin/bash FASTCGI_USER=user FASTCGI_GROUP=www-data PORT=9090 ADDRESS=127.0.0.1 PIDFILE=/var/run/php5-fastcgi.pid CHILDREN=4 PHP5=/usr/bin/php5-cgi /usr/bin/spawn-fcgi -a $ADDRESS -p $PORT -P $PIDFILE -C $CHILDREN -u $FASTCGI_USER -g $FASTCGI_GROUP -f $PHP5 

(在Ubuntu 10.04 lucid lynx上)

此设置目前不工作(502坏门户)。

当我提出要求时,我也会在varnishlog中收到一些信息

  0 CLI - Wr 200 19 PONG 1380029665 1.0 11 SessionOpen c 127.0.0.1 42489 :8181 11 Debug c herding 11 SessionClose c no request 11 StatSess c 127.0.0.1 42489 0 1 0 0 0 0 0 0 0 CLI - Rd ping 0 CLI - Wr 200 19 PONG 1380029668 1.0 0 CLI - Rd ping 

所以我尝试了另一个configuration,其中nginx围绕清漆,它像一个魅力。

(听80)nginx ==>(在9090上听)php5-fastcgi

通常人们会提出它是spawn-fcgi的错,但我认为这是在清漆的configuration

(我正在使用Ubuntu 10.04,因此使用php-fpm的选项不可用。)

这是我用netstat-nlp得到的

 tcp 0 0 0.0.0.0:8181 0.0.0.0:* LISTEN 20886/varnishd tcp 0 0 127.0.0.1:9090 0.0.0.0:* LISTEN 20989/php5-cgi tcp 0 0 127.0.0.1:6082 0.0.0.0:* LISTEN 20885/varnishd tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1478/nginx.conf tcp6 0 0 :::8181 :::* LISTEN 20886/varnishd 

Varnish了解HTTP,但要与您的PHP快速CGI守护进程连接,它必须知道CGI标准。 你不能将varnish与你的PHP守护进程连接起来。 必须有一个Web服务器Varnish可以讲话,并连接到PHP。 也许设置Varnish-Nginx-Php更有意义。

如果您正在寻找一个Php加速使用caching在Php本身,并结合基于RAM的键值存储像Memcached或Redis或其他无SQL数据库。