Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Here's my 4, going on 5 hour problem:

I've set up a WordPress multisite instance that's going to be handling sites at, and There will be N number of sites using, so I'd prefer not creating records for each. On the server, I have Nginx in front of Apache.

What I'd like to do is set up a wildcard record in Nginx to handle all of the custom domains. Right now, it looks something like this:

server {
    listen 80;
    server_name _;
    root /home/server_user/web/production;
    client_max_body_size 50M;
    client_body_buffer_size 128k;

    location / {
        access_log      off;
        proxy_pass http://localhost:8080;
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header Host $proxy_host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;


With this setup, it will pass requests to Apache and serve the dynamic content but returns 404s for all of the static content. If I change 'server_name' to '', Nginx starts serving static content again. When I change 'server_name' to '_' or any other catch-all pattern, Nginx falls on its face.

Any ideas?

share|improve this question
Which version of Nginx do you have ? – Studer Aug 13 '10 at 21:40
Define "falls on its face". It's sort of hard to debug without any actual info. – Martin Fjordvald Aug 13 '10 at 22:07
@Studer, I'm using v0.7.62 @Martin F, sorry for the confusion. What I mean is that when I define the server_name, Nginx serves static files just fine. If I use the catch-all for the server_name, then Nginx returns 404 for every static file. I know that it's partly working, however, because it's correctly proxying requests in both scenarios. – Daniel Bachhuber Aug 14 '10 at 13:08
up vote 3 down vote accepted

The solution (at least with my configuration):

In your wildcard record, the 'listen' directive should also include 'default':

listen 80 default;

Don't add a 'server_name' directive because that will cause things to break in ugly, unexpected ways.

Props to Max Cutler for helping me figure this out.

share|improve this answer
I'm on version 1.6.x and the line needs to be listen 80 default_server. – jjeaton Dec 23 '14 at 17:11

Referring to the official documentation, you have the following possibilities :

server {
  server_name  *  www.example.*;

server {
  server_name _ *;

server {
  server_name *;

Note that this has changed in 0.6.x and is now:

server {
  server_name _;

Since nginx 0.7.12, an empty server name is supported, to catch the requests without "Host" header:

server {
  server_name "";
share|improve this answer
Yes, I've read the documentation. When trying an asterisk, though, I get the following validation error: Restarting nginx: [emerg]: server name "*" is invalid in /etc/nginx/nginx.conf:127 configuration file /etc/nginx/nginx.conf test failed – Daniel Bachhuber Aug 13 '10 at 21:27
Was outdated information. * cannot be used as of 0.6 and if you use anything older than that then update ASAP! – Martin Fjordvald Aug 13 '10 at 22:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.