Empty server name argument - Can't get it to work

Hi,

I’m trying out the new 0.7.13 release which permits to use “” as server
name,
but there must be something wrong with my configuration since I can’t
get this
new feature to work.

Here’s the relevant snippet from my configuration file:

http {
access_log off;
recursive_error_pages off;
server {
listen 123.123.123.123:80;
server_name _ “”;
error_page 400 /400.html;
location /400.html {
internal;
if ($host = “”) {
access_log /var/log/access.log;
}
}
location / {
fastcgi_pass 127.0.0.1:1234;
fastcgi_intercept_errors on;
}
}
}

I thought that with this configuration I’d be able to:

  • have the application behind the fastcgi server receive requests with
    no Host:
    header specified.
  • log into access.log when my custom 400 error page is served, but only
    if no
    Host: header is present.

Instead the behaviour I’m observing is that when nginx receives a
request
without the Host: header my custom 400 page gets served without sending
the
request to the fastcgi server and nothing is logged into access.log
either.

Any suggestion would be most welcome, thank you.

Regards,
-Luigi

On Thu, Aug 28, 2008 at 08:36:19AM +0000, Luigi Perroti wrote:

listen 123.123.123.123:80;
  fastcgi_intercept_errors on;

Instead the behaviour I’m observing is that when nginx receives a request
without the Host: header my custom 400 page gets served without sending the
request to the fastcgi server and nothing is logged into access.log either.

$host is this case is “_”, server_name. You should use $http_host.

On Thu, Aug 28, 2008 at 12:46:31PM +0200, Luigi Perroti wrote:

server {
listen 123.123.123.123:80;
server_name _ “”;

}

I also tried with different syntaxes but nginx still serves the custom
400 page as soon as it receives a request with a missing Host: header.

I do not understand which requests do you want to pass to fastcgi:

  1. any successfull (not 400) requests
  2. or any successfull AND 400 requets without Host header ?

On 8/28/08, Igor S. [email protected] wrote:

  1. or any successfull AND 400 requets without Host header ?

I would like to do exactly that, is it possible?

-Luigi

On 8/28/08, Igor S. [email protected] wrote:

$host is this case is “_”, server_name. You should use $http_host.

Thanks, now logging works fine when no Host: header is specified.

Still I can’t get a request with a missing Host: header to be routed
to the fastcgi server.
As mentioned in the previous message I’m using

server {
listen 123.123.123.123:80;
server_name _ “”;

}

I also tried with different syntaxes but nginx still serves the custom
400 page as soon as it receives a request with a missing Host: header.

Regards,
-Luigi

On Thu, Aug 28, 2008 at 01:21:04PM +0200, Luigi Perroti wrote:

On 8/28/08, Igor S. [email protected] wrote:

  1. or any successfull AND 400 requets without Host header ?

I would like to do exactly that, is it possible?

Try the following:

http {
access_log off;
recursive_error_pages off;
server {
listen 123.123.123.123:80;
server_name _ “”;
error_page 400 /400.html;

location /400.html {
  internal;

  if ($http_host) {
     break;
  }

  fastcgi_pass   127.0.0.1:1234;
  access_log /var/log/access.log;
}

location / {
  fastcgi_pass   127.0.0.1:1234;
  fastcgi_intercept_errors on;
}

}
}

Even if nginx still triggers a 400 error when receiving a request with
no Host: header the solution you provided works fine and permits to
achieve the desired result.

Thank you very much for your time.

Regards,
-Luigi

On Thu, Aug 28, 2008 at 2:17 PM, Igor S. [email protected] wrote:

nginx should trigger a 400 error. Do you mean that request that was passed
to fastcgi should return 200 or so ?

No, you’re right. Indeed nginx should return a 400 error code by
default, it is quite logical. I suppose this must be what the RFC says
too.

I just didn’t think that it was still possible to override this
behaviour with the fastcgi server response.
Moreover setting recursive_error_pages to on permits to achieve even
more complex configurations.
These are very useful features indeed.

Admittedly my requirements are quite bizarre, still I’m happy to see
that nginx can easily accommodate them :slight_smile:

-Luigi

On Thu, Aug 28, 2008 at 03:01:03PM +0200, Luigi Perroti wrote:

behaviour with the fastcgi server response.
Fastcgi may ovverride 400 code only if

error_page  400 = /400.html;

In case of
error_page 400 /400.html;

nginx will send 400 anyway.

On Thu, Aug 28, 2008 at 02:06:13PM +0200, Luigi Perroti wrote:

Even if nginx still triggers a 400 error when receiving a request with
no Host: header the solution you provided works fine and permits to
achieve the desired result.

Thank you very much for your time.

nginx should trigger a 400 error. Do you mean that request that was
passed
to fastcgi should return 200 or so ?

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