假設網域為 domain.com
,
怎麼設定nginx.conf
, 實作存取abc.domain.com
的時候實際上是domain.com/abc
的內容
(瀏覽器的位址仍然顯示成abc.domain.com
)
在網路上搜的這個設定沒有用:
location / {
set $domain default;
if ( $http_host ~* "^(.*)\.domain\.com$") {
set $domain ;
}
rewrite ^/(.*) /$domain/ last;
}
过去多啦不再A梦2017-05-16 17:17:55
關鍵部分:
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 /
{
#一些配置
}
}