我刚刚在服务器上安装了Nginx,对结果非常满意,但是我仍然无法弄清楚如何插入通配符虚拟主机。
这是我想要的[目录]结构:
-- public_html (example.com) ---subdoamin 1 (x.example.com) ---subdomain 2 (y.example.com)
正如你所看到的,这是非常基本的,但是我希望能够通过简单地为一个新的子域添加一个Alogging来添加域,这个logging会立即指向public_html下的同名子目录。
networking上有东西,但我没有遇到过这样的东西。
任何帮助将不胜感激。
我会告诉你的。
server { server_name example.com www.example.com; root www/pub; } server { server_name ~^(.*)\.example\.com$ ; root www/pub/$1; }
我们有两个testing文件:
$ cat www/pub/index.html COMMON $ cat www/pub/t/index.html T
静态服务器名称:
$ curl -i -H 'Host: example.com' http://localhost/ HTTP/1.1 200 OK Server: nginx/0.8.54 Date: Wed, 23 Mar 2011 08:00:42 GMT Content-Type: text/html Content-Length: 7 Last-Modified: Wed, 23 Mar 2011 07:56:24 GMT Connection: keep-alive Accept-Ranges: bytes COMMON $ curl -i -H 'Host: www.example.com' http://localhost/ HTTP/1.1 200 OK Server: nginx/0.8.54 Date: Wed, 23 Mar 2011 08:00:48 GMT Content-Type: text/html Content-Length: 7 Last-Modified: Wed, 23 Mar 2011 07:56:24 GMT Connection: keep-alive Accept-Ranges: bytes COMMON
和正则expression式服务器名称:
$ curl -i -H 'Host: t.example.com' http://localhost/ HTTP/1.1 200 OK Server: nginx/0.8.54 Date: Wed, 23 Mar 2011 08:00:54 GMT Content-Type: text/html Content-Length: 2 Last-Modified: Wed, 23 Mar 2011 07:56:40 GMT Connection: keep-alive Accept-Ranges: bytes T
这就是我用Nginx处理虚拟主机的方法 :
server_name ~^(?<vhost>.*)$; root /srv/www/$vhost; access_log /var/log/nginx/$vhost.access.log;
我不知道为什么在父文件夹中的通配符子域名是错误的/误导。