I'm trying to figure out why a subdomain I just created in Nginx isn't using the root folder specified in it's configuration file. Below is the config file for the subdomain zeta.

server {
    listen   80; 

    root /var/www/zeta;
    server_name  zeto.mydomain.com;
    error_log  /var/log/nginx/subdomains_error.log;
    error_page 404 /404.html;
    if ($subdomain = ""){
        set $subdomain something;
        rewrite /.* /not_found;
    location / {
        index index.php index.html index.htm;
        access_log  /var/log/nginx/subdomains_access.log;
        location / {
            include        fastcgi_params;
            fastcgi_index index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root/index.php;
            access_log  /var/log/nginx/subdomains_php_access.log;

        location /public {
        location ~ \.(js|ico|gif|jpg|png|css)$ {
        location /not_found {
        location /404.html {


I have another domain file which is setup to with a wildcard subdomain and different root folder see below it's the only difference

root /var/www/account;
server_name  *.mydomain.com;

There's a text file in /etc/nginx called subdomains. A perl file reads the list of subdomains and if one exists it loads the page otherwise shows an error. I know that my wildcard subdomain file is picking up zeta as it's in the subdomains text file. It's setup like this because the server is an application and when visitors register we add their chosen subdomain to the file and reload Nginx without affecting users already on the site.

What changes can I make to the zeta file so that it'll use /var/www/zeta as the root folder and not the root folder in the wildcard config file?



If that's a copy-paste of your nginx config, your issue is a typo here:

server_name  zeto.mydomain.com;

...that should presumably read zeta.

| improve this answer | |
  • Just a typo here. I ended up copying another site config file which didn't have the if condition and it's working. – Anagio Oct 15 '12 at 12:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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