加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

nginx – 如何创建这种类型的子域:example.test.domain.com

发布时间:2020-12-13 21:15:43 所属栏目:Nginx 来源:网络整理
导读:我设法找到了重写域(我有一个通配符域指向我的服务器; * .domain.com. 如果我去test.domain.com,它的工作正常横向于: /var/www/domain.com/www/test/ 如果我做example.test.domain.com,它应该这样做: /var/www/domain.com/www/test/example/ 这是测试目录

我设法找到了重写域(我有一个通配符域指向我的服务器; * .domain.com.

如果我去test.domain.com,它的工作正常横向于:

/var/www/domain.com/www/test/

如果我做example.test.domain.com,它应该这样做:

/var/www/domain.com/www/test/example/

这是测试目录中的另一个目录.

这是我发现要使用的重写,但是我应该如何实现这两个目录子域呢?

if ($host !~* ^www.domain.domain$) {}
if ($host ~* ^([^.]+).domain.com$) {
    set $auto_subdomain $1;
}
if (-d /var/www/domain.com/www/$auto_subdomain) {}
if (-f /var/www/domain.com/www/$auto_subdomain$uri) {
    rewrite ^(.*)$/$auto_subdomain$uri;
    break;
}
最佳答案
尝试
/var/www/domain.com/www/example.test/
代替
/var/www/domain.com/www/test/example/

更新:
实际上你要做的只是第二个vhost,仅此而已.
你为什么不尝试这个nginx配置?

server {
  # Replace this port with the right one for your requirements
  listen 80 [default|default_server];  #could also be 1.2.3.4:80

  # Multiple hostnames separated by spaces.  Replace these as well.
  server_name domain.com test.domain.com example.test.domain.com *.domain.com; # Alternately: _

  root /var/www/$host;

  error_page 404 errors/404.html;
  access_log logs/star.yourdomain.com.access.log;

  index index.php index.html index.htm;

  # serve static files directly
  location ~* .(jpg|jpeg|gif|css|png|js|ico|html)${
    access_log off;
    expires max;
  }

  location ~ .php${
    include fastcgi_params;
    fastcgi_intercept_errors on;
    # By all means use a different server for the fcgi processes if you need to
    fastcgi_pass   127.0.0.1:YOURFCGIPORTHERE;
  }

  location ~ /.ht {
    deny  all;
  }
}

只需为每个域/子域创建目录即:

/var/www/domain.com
/var/www/test.domain.com
/var/www/example.test.domain.com

资料来源:http://wiki.nginx.org/VirtualHostExample

还可以从Slicehost查看关于nginx vhosts http://articles.slicehost.com/2008/5/16/ubuntu-hardy-nginx-virtual-hosts的HOWTO

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读