M
M
Matvey Mamonov2015-07-07 21:42:38
Nginx
Matvey Mamonov, 2015-07-07 21:42:38

Why can't I set up dynamic subdomains?

Actually, here is the config:

server {
    listen 80;
    server_name site *.site;
    root /var/www/site/$subdomain;
    
    set $subdomain "";
    
    if ($host ~* ^([a-z0-9-\.]+)\.site$) {
        set $subdomain $1;
    }
    
    if ($host ~* ^www.site$) {
        set $subdomain "";
    }
    
    access_log  /var/log/nginx/site.access.log;
    error_log  /var/log/nginx/site.error.log;
 
    location / {
        index index.php index.html;
        try_files \$uri \$uri/ /index.php?\$query_string;
    }
 
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

/etc/hosts:
127.0.0.1 localhost
127.0.1.1 MPCU

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

127.0.0.1 site
127.0.0.1 psql.site

It can be seen from the config that when going to psql.site/, the server should read /var/www/site/psql. This directory exists, it contains index.html, but for some reason when I go to psql.site/ it gives me
No input file specified.

Why?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2015-07-07
@eucalipt

It can be seen from the config that when going to psql.site/, the server should read /var/www/site/psql.
controversial curing
, you don’t need to do this :)
if ($host ~* ^([a-z0-9-\.]+)\.site$) {
        root /var/www/site/$1;
    }

but in general - the DRY rule does not apply to configs; in configs
, the KISS rule is strengthened,
therefore, do not be lazy and wash down a separate config for psql.site.com
server {
    server_name psql.site;
    root /var/www/site/psql;
    

    access_log  /var/log/nginx/psql.site.access.log;
    error_log  /var/log/nginx/psql.site.error.log;
 
    location / {
        index index.php index.html;
        try_files \$uri \$uri/ /index.php?\$query_string;
    }
 
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question