Alternating 404 and 200

Hi,

I’ve had this issue lately and i’ve been trying to find where did i
goof up but i’m getting clueless. I’ve recently compiled 0.8.10 (and a
few days before 0.8.9) on a Debian/linux amd64. Other than messing a
bit with the .deb i had no issues. These were the parameters i used:

–conf-path=/etc/nginx/nginx.conf
–error-log-path=/var/log/nginx/error.log
–pid-path=/var/run/nginx.pid
–lock-path=/var/lock/nginx.lock
–http-log-path=/var/log/nginx/access.log
–http-client-body-temp-path=/var/lib/nginx/body
–http-proxy-temp-path=/var/lib/nginx/proxy
–http-fastcgi-temp-path=/var/lib/nginx/fastcgi
–with-debug
–with-http_stub_status_module
–with-http_ssl_module
–with-http_xslt_module
–with-http_gzip_static_module
–with-http_secure_link_module
–add-module=/path/to/0.8.10/mod_strip
–add-module=/path/to/0.8.10/mod_zip

I cleared /etc/nginx but i didn’t touch other directories (like lib)
before installing 0.8.10, however, i don’t think that would cause this
issue. Since i had been having these issues since before 0.8.9 i
decided to go with a spartan configuration:

$ cat /etc/nginx/nginx.conf

user www-data;
worker_processes 2;

error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
}

http {
root /var/www/nginx-default;
include /etc/nginx/mime.types;
default_type application/octet-stream;

#client_body_timeout 10;
#client_header_timeout 5;
#keepalive_timeout 5 5;
#send_timeout 10;

#limit_zone reqsPerClt $binary_remote_addr 1m;
#ignore_invalid_headers on;
#recursive_error_pages on;
#sendfile on;
#server_name_in_redirect off;
#server_tokens off;

#tcp_nodelay on;
#tcp_nopush on;

#gzip on;
#gzip_static on;
#gzip_buffers 32 8k;
#gzip_comp_level 9;
#gzip_http_version 1.0;
#gzip_min_length 25;
#gzip_types text/plain application/xhtml+xml text/css;
#gzip_vary on;

log_format vpt '[$time_local - $host] $remote_addr $remote_user
[$request] ’
‘[T:$request_time S:$status BS:$body_bytes_sent GZ:$gzip_ratio]
[$http_user_agent]’;

include /etc/nginx/conf.d/.conf;
include /etc/nginx/sites-enabled/
;
}

Since this is my testing machine, i have no domains and test my sits
with subdirectories:

$ cat /etc/nginx/sites-available/default

server {
server_name localhost;
listen 127.0.0.1:8080; # only in default rcvbuf=64k backlog=128;
access_log /var/log/nginx/localhost.access.log vpt;
error_log /var/log/nginx/localhost.error.log;
#limit_conn reqsPerClt 5;
charset utf-8;

#if ($request_method !~ ^(GET|HEAD|POST)$ ) {

return 444;

#}

location / {
root /var/www/nginx-default;
index index.php index.html;
#if (!-e $request_filename) {
# rewrite ^(.*)$ /index.php?m=$request_filename break;
#}

      #if ($request_uri ~*

(^/|/site3/|/intranet/|.html|.php|.jpg|.png|.css|favicon.ico|robots.txt)$
) {
# break;
#}
#return 444;
}

location = /favicon.ico {
return 204;
}

error_page 404 /40x.html;
location = /40x.html {
root /var/www/nginx-default;
}

error_page 403 /403.html;
location = /403.html {
root /var/www/nginx-default;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/nginx-default;
}

location ~ .(php|html)$ {
fastcgi_pass localhost:8888;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
/var/www/nginx-default$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT /var/www/nginx-default;
fastcgi_intercept_errors on;
include fastcgi_params;
}
}

The issue is: if i reload repeatedly (hitting the reload button on my
browser repeatedly, at a rate of about 5-6 hits per second), under
given circumstances, half the time nginx will reply with a normal 200
(and 304 for static files), then for another half of the same time
it’ll reply with the default 404 page (instead of the configured 404
page). Then 200, then 404, … If i slow down the reloads, the 200-404
cycle slows down as well, and vice-versa.

  • at my docroot i have a very basic index.html, just the necessary to
    show

    Test

    . I can reload all i want, the issue seldom occurs.
  • i have a very basic html+php site and, again, the issue seldom
    occurs, usually just after i changed the URL from one site to another.
  • i have another basic php+xhtml site. Reloading
    /site3/index.php?param=value will give the aforementioned results
    every time.

I haven’t touched my fastcgi configuration (although i have upgraded
my system lately). I was fiddling with the .conf files at the time but
even going back to basic conf i still get this issue. I compiled from
source and installed using checkinstall but i don’t think that would
interfere. So, i’m not sure this is because of nginx or my system, or
the 3rd site, or the fastcgi or what…

I’m kinda lost in finding where the hell did i screw up. Any hints?
TIA,
Nuno Magalhães

On Fri, Aug 28, 2009 at 02:22:04PM +0100, Nuno Magalh??es wrote:

–lock-path=/var/lock/nginx.lock
–add-module=/path/to/0.8.10/mod_strip
worker_processes 2;
include /etc/nginx/mime.types;
#sendfile on;
#gzip_http_version 1.0;
}
error_log /var/log/nginx/localhost.error.log;
#if (!-e $request_filename) {

location = /403.html {
fastcgi_index index.php;
given circumstances, half the time nginx will reply with a normal 200

  • i have another basic php+xhtml site. Reloading
    I’m kinda lost in finding where the hell did i screw up. Any hints?
    Do you see these 404’s in access_log and error_log ?

I’m sorry, i didn’t notice your reply (too many mailing lists and a
web client…).

2009/8/28 Igor S. [email protected]:

Do you see these 404’s in access_log and error_log ?

Yes, both the 200 (and following 304) and the 404 error show up in the
access log. I had forgotten about the error log! Turns out the 404 are
because there was no 50x.html, which is now displayed instead of my
custom 404 page. So the true error is 502 but i’m not running nginx as
a proxy, it’s the only http server.

The error is this:
2009/09/02 12:03:32 [error] 8296#0: *79 recv() failed (104: Connection
reset by peer) while reading response header from upstream, client:
127.0.0.1, server: localhost, request: “GET
/subfolder/index.php?var=param HTTP/1.1”, upstream:
“fastcgi://127.0.0.1:9000”, host: “localhost:8080”, referrer:
http://localhost:8080/subfolder/index.php

Although i kind of suspected it (because a simple html file didn’t do
this), i didn’t assume cgi would be the problem since i haven’t
touched its configuration in ages. I did upgrade my Debian, and the
/etc/nginx/fastcgi_params was indeed replaced to the default. However,
i (think i) had only removed $nginx_version from SERVER_SOFTWARE, but
i’m not sure.

This is the current:
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;

PHP only, required if PHP was built with --enable-force-cgi-redirect

fastcgi_param REDIRECT_STATUS 200;

(I actually don’t know if PHP was built with that, but i assume
phpinfo() and finding text will answer.)

My current nginx is compiled from 0.8.10 source although i used some
files from the Debian package (for logrotate, pre/post-install
scripts, boot scripts and what not), creating a new .deb package (with
checkinstall). Maybe that interfered with the system upgrade and or
nginx/php-cgi configurations.

I’m probably overflowing some buffer of filling some cache or
something on cgi. How can i solve this?

While i was trying to figure out if it was nginx or php i installed
Apache, which ended up confusing me even more… Anyway, i have the
following directories in /var/www: apache, nginx_default, site01. I
changed my nginx.conf and my server{ } so that both have root /var/www
and restarted nginx (i’ve also tried stop/start). I use URLs like
http://localhost:8080/site01”, but nginx is still serving the site
from /var/www/nginx_default/site01, not /var/www/site01 as i expected.
What am i doing wrong this time? :slight_smile:

I’m sorry i didn’t check the error.log sooner. thanks for your help.
Nuno Magalhães