empty reply from server

Maxim Dounin mdounin at mdounin.ru
Sun May 8 02:34:23 MSD 2011


Hello!

On Fri, May 06, 2011 at 09:38:46AM -0400, yellowbox9 wrote:

> I'm setting up a new nginx environment and I'm having issues with 404's.
> When I use curl to request a file that I know does not exist, nginx
> responds back with an empty reply.... I would prefer a 404 not found
> with the correct http status code.

You will be surprised, but nginx returns 404 in such cases by default.

> My config:
> 
> user nobody;
> worker_processes 4;
> worker_rlimit_nofile 8192;
> events
> {
>         worker_connections 4096;
> }
> 
> http
> {
>         include mime.types;
>         default_type text/plain;
>         log_format nn '$host $remote_addr - $remote_user [$time_local] 
> ' '"$request" $status $bytes_sent ' '"$http_referer"
> "$http_user_agent"';
>         access_log /opt/nginx/logs/access.log nn;
>         error_log /opt/nginx/logs/error.log;

It's good idea to specify error_log at *global* level, not http.  
When defined at http level it will be only used for http-related 
problems, but not for generic problems.

E.g. with your config information about abnormally terminated 
workers won't reach error_log you specified, but will go to 
compiled-in default error log instead.

>         sendfile on;
>         keepalive_timeout 0;
>         server
>         {
>                 listen 80 default;
>                 root /opt/nginx/html/;
>                 index index.html index.htm index.php index.php5;
>                 include /opt/nginx/conf/location_php.conf;

Please show contents of the included file.

>         }
>         include /opt/nginx/conf/vhosts/*.conf;

And please show contents of these includes, if there are any.

> }
> 
> The html root dir:
> 
> bash> ls /opt/nginx/html/
> 404.html  50x.html  empty.html  foobar  index.html  ping
> 
> The curl request:
> 
> curl -v http://localhost/index.html2
> * About to connect() to localhost port 80
> *   Trying 127.0.0.1... connected
> * Connected to localhost (127.0.0.1) port 80
> > GET /index.html2 HTTP/1.1
> > User-Agent: curl/7.15.5 (i386-redhat-linux-gnu) libcurl/7.15.5
> OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
> > Host: localhost
> > Accept: */*
> > 
> * Empty reply from server
> * Connection #0 to host localhost left intact
> curl: (52) Empty reply from server
> * Closing connection #0
> 
> The access log:
> localhost 127.0.0.1 - - [06/May/2011:09:35:17 -0400]  "GET /index.html2
> HTTP/1.1" 200 0 "-" "curl/7.15.5 (i386-redhat-linux-gnu) libcurl/7.15.5
> OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5" - For some reason returning http
> status code 200?
> 
> The error log:
> 2011/05/06 09:35:17 [error] 9879#0: *9312 open()
> "/opt/nginx/html/index.html2" failed (2: No such file or directory),
> client: 127.0.0.1, server: , request: "GET /index.html2 HTTP/1.1", host:
> "localhost"
> 
> I don't understand what I'm doing wrong here... any thoughts?

Empty response indicate either "return 444" somewhere in your 
config or some error occured (and it's impossible to return error 
to the client).

Status 200 in your access log indicate that your set some 
error_page processing somewhere in your config.

It's impossible to say anything for sure from information you 
provided (basically there is no full error log, and no full 
config), but I assume you did something like

    error_page 404 =200 /error;

    location /error {
        return 444;
    }

which will lead to the exactly the same results as you described.

Maxim Dounin



More information about the nginx mailing list