[BUG] incorrect server address passed to PHP through FastCGI(from nginx version 0.7.36)
Igor Sysoev
is at rambler-co.ru
Tue Mar 17 23:00:02 MSK 2009
On Tue, Mar 17, 2009 at 03:56:38AM +0000, Kinch Zhang wrote:
> We're using nginx with PHP through FastCGI, and from nginx 0.7.36 on, the PHP
> global variable $_SERVER["SERVER_ADDR"] is always 0.0.0.0, but with the same PHP
> configuration, nginx 0.7.35 passed the correct server address, so I think
> there's a bug in nginx 0.7.36+.
The attached patch should fix the bug.
--
Igor Sysoev
http://sysoev.ru/en/
-------------- next part --------------
Index: src/http/ngx_http_request.c
===================================================================
--- src/http/ngx_http_request.c (revision 1891)
+++ src/http/ngx_http_request.c (working copy)
@@ -310,8 +310,6 @@
* is required to determine a server address
*/
- c->local_sockaddr = NULL;
-
if (ngx_http_server_addr(r, NULL) != NGX_OK) {
ngx_http_close_connection(c);
return;
Index: src/http/ngx_http_core_module.c
===================================================================
--- src/http/ngx_http_core_module.c (revision 1891)
+++ src/http/ngx_http_core_module.c (working copy)
@@ -1789,14 +1789,39 @@
ngx_int_t
ngx_http_server_addr(ngx_http_request_t *r, ngx_str_t *s)
{
- socklen_t len;
- ngx_connection_t *c;
- u_char sa[NGX_SOCKADDRLEN];
+ socklen_t len;
+ ngx_uint_t addr;
+ ngx_connection_t *c;
+ u_char sa[NGX_SOCKADDRLEN];
+ struct sockaddr_in *sin;
+#if (NGX_HAVE_INET6)
+ ngx_uint_t i;
+ struct sockaddr_in6 *sin6;
+#endif
c = r->connection;
- if (c->local_sockaddr == NULL) {
+ switch (c->local_sockaddr->sa_family) {
+#if (NGX_HAVE_INET6)
+ case AF_INET6:
+ sin6 = (struct sockaddr_in6 *) c->local_sockaddr;
+
+ for (addr = 0, i = 0; addr == 0 && i < 16; i++) {
+ addr |= sin6->sin6_addr.s6_addr[i];
+ }
+
+ break;
+#endif
+
+ default: /* AF_INET */
+ sin = (struct sockaddr_in *) c->local_sockaddr;
+ addr = sin->sin_addr.s_addr;
+ break;
+ }
+
+ if (addr == 0) {
+
len = NGX_SOCKADDRLEN;
if (getsockname(c->fd, (struct sockaddr *) &sa, &len) == -1) {
More information about the nginx
mailing list