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

I'm setting up Nginx with PHP 5.3 for multiple websites running wordpress for example. I just added a new site and it's being redirected to the default welcome page. I can't see any 'real' errors in the logs.

Here's my abbreviated nginx.conf :

http {
    access_log /var/log/nginx_access.log;
    index index.php index.html;

    server {
        listen          80 default_server;
        server_name     _;
        root            /opt/nginx/html;

        location / {

    server {
        listen          80;
        server_name *;                      
        rewrite ^       $scheme://$request_uri? permanent;

    server {
        listen       80;
        root /home/example/;

        location / {

        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_pass   unix:/var/run/php5-fpm/example.sock;
            fastcgi_index  index.php;
            include        fastcgi_params;

share|improve this question
OK, it seems there wasn't anything wrong with the nginx.conf file. It was PHP5-FPM failing because it was missing a directory configured for it's log file! – Mark Robinson Jun 4 '12 at 15:20

As pointed by comments, the listen directive in the server block define it as the default (source:

listen       80  default_server;

The following declaration is meant as an invalid server name (source: (so it never intersect any of your valid domain) :

Server_name _; 

To fix you problem, make sure you have a server block with listen (port) and server_name (virtual host) - this one will be triggered first as you go from 'more precise to less precise' when you do virtual host names matching in nginx:

Listen 80;
share|improve this answer
Thanks for the reply @cloudweavers, I'd like to keep the default as a fallback say if the IP address is accessed instead of a domain name - is that possible? – Mark Robinson Jun 4 '12 at 11:57
This is incorrect. The default_server listen flag is what marks a server as default. server_name _ has no special meaning. – kolbyjack Jun 4 '12 at 12:07
I just tried commenting out the default server block and nothing changed - i still got the default welcome page for my domain instead of it's index.php page – Mark Robinson Jun 4 '12 at 12:23
Wow, not enough coffee here! I've updated the answer with some more accurate information... – CloudWeavers Jun 4 '12 at 12:50
Thanks for the update @CloudWeavers this doesn't seem to solve my problem as I already had a server_name with the specific domain ( in my example) which isn't catching it as far as I can tell. – Mark Robinson Jun 4 '12 at 14:11

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.