A catch-all and named server in a single configuration

Hi all,

I want to setup a catch-all server for all domains referred to that
ip. (It should pass various domains to a rails app).
Therefore I use:

server {
server_name _;

do some stuff

}

Now I there is one exception for this, there is a special domain where
I want a directory listing for so I added another server entry:

server {
server_name exceptional_domain.com

do some dir listing stuff

}

server {
server_name _*;

do some stuff

}

After restarting nginx, all domains where caught in the first entry,
showing the dir listing! None of the domains hit rails anymore!
I solved the problem by adding a conditions to the catch-all entry,
which is pretty ugly when I want to add some additional vhosts, but
it’ll do for now.

Is this behavior a bug, or is it intended?

  • Matt

p.s. this is nginx-0.4.13-2 on debian etch

On Fri, Jun 13, 2008 at 12:37:59PM +0200, Matthijs L. wrote:

I want a directory listing for so I added another server entry:

p.s. this is nginx-0.4.13-2 on debian etch
The first server is default server for given ip:port pair.
You may explicitly set any server as default using the “default” keyword
in the listen directive:

 server {
     listen   ip:port default;

Igor S. wrote:

On Fri, Jun 13, 2008 at 12:37:59PM +0200, Matthijs L. wrote:

I want a directory listing for so I added another server entry:

p.s. this is nginx-0.4.13-2 on debian etch
The first server is default server for given ip:port pair.
You may explicitly set any server as default using the “default” keyword
in the listen directive:

 server {
     listen   ip:port default;

That setup doesn’t work for me.
When I add the “listen ip:port default;” directive for the catch-all
service, my dir listing stops working at all.
Maybe I’m not making myself clear enough. I’m searching for setup that
for instance allows me to proxy all requests for all hosts, but also be
able to make an exception for a certain host.

e.g. requests for ‘*’ should be proxied to apache, except for a request
for ‘exceptional_domain.com’, which should be proxied to
http://mongrel-cluster.

I’m aware that I’m running a somewhat old version of Nginx, have I ran
into a bug that already has been fixed?

  • Matt

Almir K. wrote:

you are doing something wrong, as that setup works without problems for
me. most of my sites are proxied back to apache, while some of them are
handled by nginx, example:

Well that’s good to know, at least it is something I can fix myself!
Thanks for posting your example setup, I’ll copy-cat it and try it for
myself.

On Wed, Jul 02, 2008 at 03:32:24PM +0200, Matthijs L. wrote:

 server {

for ‘exceptional_domain.com’, which should be proxied to
http://mongrel-cluster.

I’m aware that I’m running a somewhat old version of Nginx, have I ran
into a bug that already has been fixed?

you are doing something wrong, as that setup works without problems for
me. most of my sites are proxied back to apache, while some of them are
handled by nginx, example:

server {
listen 195.246.11.19:80 default;
location / {
proxy_pass http://127.0.0.1:80;
proxy_max_temp_file_size 10M;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For
$proxy_add_x_forwarded_for;
limit_conn one 10;
}
}
server {
listen 195.246.11.19:80;
server_name break-festival.org www.break-festival.org
break-festival.com www.break-festival.com;
location / {
fastcgi_pass localhost:34003;
include /etc/nginx/django-fcgi.conf;
rewrite ^/favicon.ico$ /static/favicon.ico last;
}
location /br-media {
alias /home/break/br/media;
}
location /media {
alias /home/break/br/django/contrib/admin/media;
}
location /admin-media {
alias /home/break/br/django/contrib/admin/media;
}
access_log /home/break/access.log;
error_log /home/break/error.log;
}