nginx Автоматическая генерация поддоменов

nginx Автоматическая генерация поддоменов
Вот конфиг для /etc/nginx/sites-available/default

server {
listen 80;

index index.php;

server_name example.com *.example.com;
root /www/$subdomain;
set $subdomain «»;

if ($host ~* ^([a-z0-9-\.]+)\.localhost$) {
set $subdomain $1;
}
if ($host ~* ^localhost$) {
set $subdomain «»;
}

charset utf-8;

location / {
try_files $uri $uri/ /index.php;
}

location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;

fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}

Теперь можно просто создавать в www папки и они будут доступны как поддомены *.localhost

Например:
/www/some
some.localhost

more:http://badphpcoder.blogspot.com/2014/01/nginx.html

Разумеется предварительно нужно будет поправить /etc/hosts

Leave a Reply

Ваш адрес email не будет опубликован. Обязательные поля помечены *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>