eucalipt
@eucalipt
Самоделкин.

Почему не получается настроить динамические поддомены?

Собственно, вот такой вот имеется конфиг:
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


Из конфига видно, что при переходе на psql.site/ сервер должен читать /var/www/site/psql. Этот каталог есть, в нем index.html, но почему-то при переходе на psql.site/ мне выдает
No input file specified.

Почему?
  • Вопрос задан
  • 248 просмотров
Решения вопроса 1
sim3x
@sim3x
Из конфига видно, что при переходе на psql.site/ сервер должен читать /var/www/site/psql.
спорное отверждение

вот так делать не нужно :)
"root" directive is not allowed here in

if ($host ~* ^([a-z0-9-\.]+)\.site$) {
        root /var/www/site/$1;
    }


а вообще - на конфиги не распространяется правило DRY
в конфигах усиливается правило KISS

потому не поленись и запили отдельний конфиг для 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;
    }
}
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы