Serveur - Comment définir un répertoire comme nom de domaine de deuxième niveau dans nginx ?
巴扎黑
巴扎黑 2017-05-16 17:15:55
0
3
469

Supposons que le nom de domaine soit domain.com,

Comment configurer nginx.conf, 实现 访问 abc.domain.com 的时候实际是 domain.com/abc的内容
(浏览器的地址仍然显示成abc.domain.com )

Cette configuration recherchée sur Internet ne sert à rien :

location / { 
    set $domain default; 
    if ( $http_host ~* "^(.*)\.domain\.com$") { 
                  set $domain ; 
    } 
    rewrite ^/(.*)    /$domain/ last; 
}
巴扎黑
巴扎黑

répondre à tous(3)
过去多啦不再A梦

Partie clé :

server
{
    listen   80;
    server_name   www.domain.com;
    root   /var/www/html;
    index  index.php index.html index.htm;

    location /abc
    {
        if ( $host !~* "abc.domain.com" )
        {
            return 404;  #防止有人访问www.domain.com/abc看到abc二级域名的页面,只允许访问abc.domain.com查看
        }
    }
}

server
{
    listen   80;
    server_name   abc.domain.com;
    root   /var/www/html/abc;
    index  index.php index.html index.htm;

    location /
    {
        #一些配置
    }
}
小葫芦
location / { 
    #申明domain变量 
    set $domain default;
    #正则提取出二级域名
    if ( $http_host ~* "^(.*)\.domain\.com$") { 
        #把二级域名赋值给domain变量
        set $domain ; 
        #设置rewrite规则,把/下的所有请求转发到http://domain.com/$domain/下。
        rewrite ^/(.*)$    http://domain.com/$domain/ last; 
    } 

}
phpcn_u1582

Construisez simplement un autre serveur ! C'est tellement compliqué, à la fois régulier et réécrit.

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!