Working with include directive and wildcards?

Igor Sysoev is at rambler-co.ru
Sun Jun 29 11:43:05 MSD 2008


On Sat, Jun 28, 2008 at 07:43:35PM -0700, Ian Sefferman wrote:

> I'm trying to figure out an issue with the include directive and
> wildcards in v0.5.33 (on Ubuntu Hardy).
> 
> My nginx.conf file looks like so (trimmed):
> 
> http {
>   include /u/apps/*/current/config/nginx.conf;
> }
> 
> Then, I have two directories within /u/apps, each with their own config:
> /u/apps/bar/current/config/nginx.conf (trimmed):
> server {
>   listen 80;
>   server_name _ *;
>   location / {
>     proxy_pass http://bar_mongrel;
>   }
> }
> 
> /u/apps/foo/current/config/nginx.conf (trimmed):
> server {
>   listen 80;
>   server_name foo.domain.com;
>   location {
>     proxy_pass http://foo_mongrel;
>   }
> }
> 
> This code never reaches the bar server, it only ever returns foo.
> However, when I change my nginx.conf to:
> http {
>   include /u/apps/bar/current/config/nginx.conf;
>   include /u/apps/foo/current/config/nginx.conf;
> }
> 
> ... it works perfectly (and I change the order of those two and it
> still works fine).
> 
> I'm wondering what I'm doing wrong here?

Wildcard includes are not sorted. Thus, probably, bar was included after foo.
"server_name ... *" is not default server, it's ugly hack, and it had been
removed in 0.6.x. The default server was alwayes set in listen directive:

     listen 80 default;

If you do not set it explicitly, it will be first server. So:

-   listen 80;
-   server_name _ *;
+   listen 80 default;
+   server_name _;


-- 
Igor Sysoev
http://sysoev.ru/en/





More information about the nginx mailing list