我想所有子域映射到一个特定的文件夹和404如果什么都不存在。 所以如果我有一个WordPress的安装,我想Nginx看到ANTHING.MYSITE.com,并尝试从/var/log/mysite/subdomaindir/ANYTHING托pipe文件
我怎么能这样做?
我不完全确定你在寻找哪种scheme,但是这两者都很容易实现。 指定'404如果不存在'不应该是必要的,因为这是nginx的默认行为(尽pipe如此,你可以自定义错误页面)。
scheme1:将所有子域redirect到SAME文件夹:
server { server_name *.mysite.com; root /var/www/mysite/subdomaindir/; ...your other blocks/directives }
scheme2:将所有子域redirect到各自的文件夹:
server { server_name ~^(?<sub>.+)\.mysite\.com$; root /var/www/mysite/subdomaindir/$sub; ...your other blocks/directives }