Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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     example.com *.example.com;                      
        rewrite ^       $scheme://www.example.com$request_uri? permanent;
    }

    server {
        listen       80;
        server_name  www.example.com;
        root /home/example/example.com;

        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

1 Answer 1

As pointed by comments, the listen directive in the server block define it as the default (source: http://nginx.org/en/docs/http/request_processing.html):

listen       80  default_server;

The following declaration is meant as an invalid server name (source: http://nginx.org/en/docs/http/server_names.html) (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;
Server_name your-domain-name.com;  
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
1  
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 (www.example.com in my example) which isn't catching it as far as I can tell. –  Mark Robinson Jun 4 '12 at 14:11

Your Answer

 
discard

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.