我们正在转向Apache的一些Nginx服务器。 虽然我们已经使用Nginx的各个网站,它已经在一个最基本的configuration。 但是,我们托pipe的“网站”(实际上是多个)之一是一个沙箱types的网站,以便我们的开发人员可以login到服务器创build一个目录,并且他们有一个网站启动并运行。 我想弄清楚如何用Nginx来复制这个,但是到目前为止我还是无法把头围住。 任何帮助,将不胜感激。
服务器目录设置示例:
/home/[USER]/sandbox/site1 /home/[USER]/sandbox/site2 ... etc.
Apacheconfiguration:
<VirtualHost *:80> ServerName example.com ServerAlias *.example.com ServerAlias *.*.example.com RewriteEngine on RewriteCond %{HTTP_HOST} ^(.*)\.(.*)\.example\.com$ [NC] RewriteRule ^(.*)$ /home/%1/sandbox/%2/$1 [L] <Directory /> AllowOverride All Require all granted </Directory> </VirtualHost>
结果域:
[USER].site1.example.com [USER].site2.example.com .... etc.
在Nginx中parsing主机并在内部正确路由到所述目录会是什么样子?
也许这样的事情:
server { server_name ~^(?<user>\w+)\.(?<site>\w+)\.example\.com$; #Then you can use $user and $site variables in config, eg: root /home/$user/sandbox/$site; }