malloc() errors - (some type of redirect loop?)
gnexus
nginx-forum at nginx.us
Sun Sep 12 18:56:11 MSD 2010
Hi everyone,
I am new to the mailing list and have only been using Nginx a few
months, so please bear with me.
We are currently getting MANY errors such as this:
2010/09/07 17:58:18 [emerg] 8851#0: *4086 malloc() 4294967295 bytes
failed (12: Cannot allocate memory), client: 66.249.71.238, server:
xxxx.net, request: "GET /robots.txt HTTP/1.1", host: "www.xxxxx.net"
These errors started occurring after changes to our site config.
We originally set up Nginx as only a reverse proxy, to forward to other
machines, so [b]nginx.conf[/b] is as such:
[code]
server {
listen 80;
server_name _;
location / {
resolver 192.168.1.1;
proxy_pass http://$host$uri;
proxy_intercept_errors on;
}
[/code]
That was working VERY well (thanks to the Nginx developers for that!),
so we decided to add a local config on the gateway machine to serve up
some other stuff:
so this is the [b]rest of current nginx.conf[/b]:
[code]
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
#root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
/home/httpd/html$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
[/code]
this is [b]fastcgi_params[/b]:
[code]
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 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;
[/code]
The site config then was as such:
[b]cat /etc/nginx/sites-enabled/xxxxxx.net[/b]
[code]
server {
listen 80;
server_name xxxxxx.net;
access_log /home/httpd/log/access.log;
error_log /home/httpd/log/error.log;
location / {
root /home/httpd/html/xxxxxxx.net;
index index.html;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
/home/httpd/html/xxxxxx.net/$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
}
[/code]
At this point everything was still working fine. (Thanks again Nginx
developers!!)
But we are also running our Webmail, and a small download server, on the
gateway. Url's such as:
[b]http://www.xxxxxxx.net/webmail[/b] and
[b]http://www.xxxxxxxxxx.net/download[/b]
proved to be inconvenient for our users, as they were used to the
previous url format such as:
[b]http://webmail.xxxxxxx.net.[/b]
We also wanted to group subdomains such as webmail and download into
their own respective independent directories for maintenance and
security reasons. We decided upon a directory hierarchy such as this:
[code]
/home/httpd/html
/home/httpd/html/xxxxx.net
/home/httpd/html/xxxxx.net/www
/home/httpd/html/xxxxx.net/webmail
/home/httpd/html/xxxxx.net/download
[/code]
Since Nginx can use regex to extract the subdomain, we decided to use a
regex if statement in the domain config to set the root directory for
each subdomain. That simplifies the config and makes adding subdomains a
simple matter of adding content. So now our domain config is as such:
[b]cat /etc/nginx/sites-enabled/xxxxxx.net[/b]
[code]
server {
listen 80;
server_name xxxxxxxx.net www.xxxxxxx.net *.xxxxxx.net;
access_log /home/httpd/log/xxxxxxxxxx.net-access.log;
error_log /home/httpd/log/xxxxxxxxx.net-error.log;
# Extracts the subdomain to a variable
if ($host ~ "^(.*).xxxxxxxx.net") {
set $sub $1;
set $domain $2;
}
# If the directory doesn't exist then redirect to the main-page
if (!-d /home/httpd/html/xxxxxxx.net/$sub) {
rewrite . http://www.xxxxxxxxxx.net/ redirect;
}
location / {
root /home/httpd/html/xxxxxxxxx.net/$sub;
index index.html;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
/home/httpd/html/xxxxxxxxx.net/$sub$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
# redirect 404 server error pages to the static page
# error_page 404 notfound.htm;
}
[/code]
At this point is when we started getting the malloc() errors. Sometimes
the pages will load properly. At other times random images will be
missing on the page. Reloading the page will cause the missing images to
randomly change. Other times a 500 error will occur. The byte size of
the file in the malloc() error will depend upon the file creating the
error, but the size will stay consistent per file and always be in the
MB/GB size range. All files on which the errors occur, including images,
are no more than 10kB. Also the error pages do not work, and that is why
they are commented out.
Since the errors only started occurring only after we made the recent
changes we suspect the problem is due to some type of error in our regex
expressions. I have a hard time getting a good grip on those. So the
regex code we are using was copied from other nginx configs posted on
the Web.
Thanks in advance for any assistance.
Posted at Nginx Forum: http://forum.nginx.org/read.php?2,129739,129739#msg-129739
More information about the nginx
mailing list