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 having around 800 sites on an nginx server. All these vhosts are defined within one file that is included. You can see some examples of vhosts below (the other 800 looks exactly the same except domain names). For every domain name there is a www. and without www. server section.

Everything works pretty well. Except for some requests to some domain (example: domain2), the request is redirected to domain2 for some reason. See the example wget request below.

Somebody that can help me ?

Vhost config

server {
    listen   80; 

    root /srv/www/core/public_html/src/public/;
    error_log /srv/www/core/logs/error.log;
    index index.php;

    server_name domain1.com;

    location / {
        if (!-e $request_filename) {
            rewrite ^.*$ /index.php last;
        }
    }

    location ~ .(php|phtml)$ {
        fastcgi_param SCRIPT_FILENAME /srv/www/core/public_html/src/public$fastcgi_script_name;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi_params;
    }
}

server {
    listen   80; 

    root /srv/www/core/public_html/src/public/;
    error_log /srv/www/core/logs/error.log;
    index index.php;

   server_name www.domain1.com;

    location / {
        if (!-e $request_filename) {
            rewrite ^.*$ /index.php last;
        }
    }

    location ~ .(php|phtml)$ {
        fastcgi_param SCRIPT_FILENAME /srv/www/core/public_html/src/public$fastcgi_script_name;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi_params;
    }
}
server {
    listen   80; 

    root /srv/www/core/public_html/src/public/;
    error_log /srv/www/core/logs/error.log;
    index index.php;

    server_name domain2.com;

    location / {
        if (!-e $request_filename) {
            rewrite ^.*$ /index.php last;
        }
    }

    location ~ .(php|phtml)$ {
        fastcgi_param SCRIPT_FILENAME /srv/www/core/public_html/src/public$fastcgi_script_name;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi_params;
    }
}

server {
    listen   80; 

    root /srv/www/core/public_html/src/public/;
    error_log /srv/www/core/logs/error.log;
    index index.php;

   server_name www.domain2.com;

    location / {
        if (!-e $request_filename) {
            rewrite ^.*$ /index.php last;
        }
    }

    location ~ .(php|phtml)$ {
        fastcgi_param SCRIPT_FILENAME /srv/www/core/public_html/src/public$fastcgi_script_name;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi_params;
    }
}

Wget Tests to the domains

2013-01-18 13:42:29 (199 KB/s) - `index.html.1367' saved [100308]

--2013-01-18 13:42:31--  http://domain1.com/
Resolving domain1.com (domain1.com)... 66.228.42.113
Connecting to domain1.com (domain1.com)|66.228.42.113|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: http://www.domain2.com/ [following]
--2013-01-18 13:42:32--  http://www.domain2.com/
Resolving www.domain2.com (www.domain2.com)... 69.164.223.55
Connecting to www.domain2.com (www.domain2.com)|69.164.223.55|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: `index.html.1368'

    [    <=>                                                                                                                                                                                                                               ] 100,308      134K/s   in 0.7s    

2013-01-18 13:42:33 (134 KB/s) - `index.html.1368' saved [100308]

--2013-01-18 13:42:35--  http://domain1.com/
Resolving domain1.com (domain1.com)... 66.228.42.113
Connecting to domain1.com (domain1.com)|66.228.42.113|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: `index.html.1369'

    [   <=>                                                                                                                                                                                                                                ] 91,031       179K/s   in 0.5s    

2013-01-18 13:42:37 (179 KB/s) - `index.html.1369' saved [91031]

--2013-01-18 13:42:39--  http://domain1.com/
Resolving domain1.com (domain1.com)... 66.228.42.113
Connecting to domain1.com (domain1.com)|66.228.42.113|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: `index.html.1370'

    [   <=>                                                                                                                                                                                                                                ] 91,031       179K/s   in 0.5s    

2013-01-18 13:42:40 (179 KB/s) - `index.html.1370' saved [91031]

--2013-01-18 13:42:42--  http://domain1.com/
Resolving domain1.com (domain1.com)... 66.228.42.113
Connecting to domain1.com (domain1.com)|66.228.42.113|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: `index.html.1371'

You can see that on 2013-01-18 13:42:30 I restarted the nginx server. After that everything works correct again. Now it works correct again, but after some time it looks going wrong again.

Maybe this can have impact: Every 2 minutes I do a nginx reload trough cron to load new vhost files added to the file.

Hope someone can help me!

share|improve this question
    
Out of interest, why are you duplicating the blocks for the www. subdomain? You can just do server_name www.domain.com domain.com; if the rest of the block is identical. For your actual 301 issue, what does /var/log/nginx.log say about the requests? –  Xyon Jan 18 '13 at 13:35
    
I had the server_names in one line first and was thinking that having 2blocks could solved my problem, but it didn't. I can see the following in my access log => IP - - [18/Jan/2013:13:42:29 +0100] "GET / HTTP/1.1" 301 178 "-" "Wget/1.13.4 (linux-gnu)" –  wloockx Jan 18 '13 at 13:59
    
What happens if you set the log level to debug and log it then? –  Xyon Jan 18 '13 at 14:02
    
How do I set the access log on debug ? –  wloockx Jan 18 '13 at 14:12
    
In nginx.conf, there's probably already a line for error_log, followed by a file path - add on the word debug to that directive. –  Xyon Jan 18 '13 at 14:15
show 2 more comments

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.