| From | Sent On | Attachments |
|---|---|---|
| Luigi Perroti | Aug 21, 2008 8:19 am | |
| Igor Sysoev | Aug 21, 2008 8:26 am | |
| Luigi Perroti | Aug 21, 2008 9:16 am | |
| Igor Sysoev | Aug 21, 2008 9:45 am | |
| Luigi Perroti | Aug 21, 2008 10:21 am | |
| Igor Sysoev | Aug 21, 2008 10:37 am | |
| Luigi Perroti | Aug 21, 2008 11:20 am |
| Subject: | Re: Condition to match a missing "Host:" header | |
|---|---|---|
| From: | Igor Sysoev (is-G...@public.gmane.org) | |
| Date: | Aug 21, 2008 9:45:17 am | |
| List: | ru.sysoev.nginx | |
On Thu, Aug 21, 2008 at 04:16:53PM +0000, Luigi Perroti wrote:
Igor Sysoev <is@...> writes:
Why do you need to test it ? Have you tried the configuration in my previous mail ?
Yes, I tried what you suggested. Now I have a better understanding of how nginx works, thank you.
As of now I've come up with a configuration file that works fine for the application that I'll have to run.
The only thing is that, with this configuration, when no "Host:" header is sent by the client nginx will handle this with a 400 code directly. The application won't receive the request. Since this application does access logging by itself I disabled access logging in nginx.
But I would like to turn it back on for requests where no Host header is specified. Otherwise I'd have no way to know about these requests.
I also do this when my custom error pages are called directly.
The relevant part of my config file can be found here:
http://pastebin.com/mc05d231
Note that although it might be written better this does exactly what I want. Except for the fact that I can't have nginx log to access.log the requests with no Host header, and I can't get my application to handle them either.
You need just:
location = /400.html { root /www/errors; internal; access_log /var/log/nginx/access.log; }
Also, any "if ($request_uri = '/404.html')" means that you should write
location = /404.html {
instead.
BTW, in 0.7.12 the special server_name "" will allow to handle requests without Host not in default listening server:
server { listen 80 default; server_name _; }
server { listen 80; server_name www.example.com ""; }
-- Igor Sysoev http://sysoev.ru/en/





