我设法找到了重写域(我有一个通配符域指向我的服务器; * .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/
原文链接:https://www.f2er.com/nginx/435335.html/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