Upstream with fastcgi_pass

I have a problem when use upstream,my config is like this(nginx
version:0.8.54):

upstream www.a.com {
       server 10.249.200.76:9000;
       server 10.249.200.76:9001;
 }

server{

     .....

     location ~ \.php$ {
        root           html;
        fastcgi_pass   www.a.com;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www/$host

/$fastcgi_script_name;
include fastcgi_params;
}
}

and then can success to visit www.a.com;

but when "fastcgi_pass   www.a.com;" relace  by
"fastcgi_pass $host;", visit www.a.com is failed.

 I don't know why? can somebody know?

new config like this:

upstream www.a.com {
       server 10.249.200.76:9000;
       server 10.249.200.76:9001;
 }

server{

     .....

     location ~ \.php$ {
        root           html;
        fastcgi_pass   $host;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www/$host

/$fastcgi_script_name;
include fastcgi_params;
}
}

Anybody know?

Obviously it doesn’t support variables

Sent from my iPod

I am also interested in this functionality. It seems like this feature
was included at some point. Look at this thread from 2008.

http://nginx.org/pipermail/nginx/2008-December/008751.html

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,183712,187795#msg-187795

Also found another one with a bug reported and fixed against that
patch.

http://web.archiveorange.com/archive/v/yKUXMz3KPVtsrCYTvFzI

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,183712,187796#msg-187796

Looks like the links I posted are about using variables in fastcgi_pass
directive for hostname or socket, not for upstream name.

When I tried similar configuration, I got “no port in upstream” error in
log.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,183712,187842#msg-187842

I hook nginx code,than can resolve this problem,
like this:

diff -uNr nginx-0.8.54-from/src/http/modules/ngx_http_fastcgi_module.c
nginx-0.8.54-to/src/http/modules/ngx_http_fastcgi_module.c
— nginx-0.8.54-from/src/http/modules/ngx_http_fastcgi_module.c
2010-08-03 21:35:48.000000000 +0800
+++ nginx-0.8.54-to/src/http/modules/ngx_http_fastcgi_module.c
2011-04-06 15:05:43.000000000 +0800
@@ -636,12 +636,12 @@
return NGX_ERROR;
}

  • if (url.no_port) {
  • /* if (url.no_port) {
    ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
    “no port in upstream “%V””, &url.url);
    return NGX_ERROR;
    }

+*/
u = r->upstream;

 u->resolved = ngx_pcalloc(r->pool, 

sizeof(ngx_http_upstream_resolved_t));

Just enable debug log, make your test and read log carefully. If you
need assistance, drop here your full nginx config and debug log.


Regards, Vitaly T.
System A.
U.S. +1 (206) 905-9939
Russia +7 911 094-2035

Thanks for the code. This seems to solve the problem.

Is this change safe for production? Is it possible that this change will
break something else? Is it possible to include it in a future
release/patch?

Thanks

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,183712,190231#msg-190231

On Mon, Apr 11, 2011 at 01:34:02PM -0400, msingla wrote:

Thanks for the code. This seems to solve the problem.

Is this change safe for production? Is it possible that this change will
break something else? Is it possible to include it in a future
release/patch?

Changes with nginx 0.9.7 04 Apr
2011

   [ ... ]

*) Bugfix: a case when a backend in "fastcgi_pass", "scgi_pass", or
   "uwsgi_pass" directives is given by expression and refers to a
   defined upstream.


Igor S.

Great. Thanks. Much appreciated.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,183712,190295#msg-190295

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs