我做了一些阅读,我找不到我的问题的答案,因为它有一个关键组成部分是不同于大多数情况下。 它和其他故事一样:我需要将.htaccess迁移到nginxconfiguration中,如果不是这样,nginx服务器设置为使用dynamic主机:
server { listen 80; server_name ~^(www\.)?(?<sname>.+?).server.company.com$; root /var/www/$sname/current/public; index index.html index.htm index.php; location / { try_files $uri $uri/ /index.php$is_args$args; } location ~* \.(gif|png|bmp|ico|flv|swf|exe|html|htm|txt|css|js) { add_header Cache-Control public; add_header Cache-Control must-revalidate; expires 7d; } location ~ \.php$ { fastcgi_pass unix:/var/run/php/php7.1-fpm.sock; include fastcgi_params; fastcgi_param DOCUMENT_ROOT $realpath_root; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_index index.php; } location ~ /\.ht { deny all; } }
这样做是为了根据目录在单个子域上运行多个项目。 问题是这些项目之一(让我们称之为project.domain.company.com)是一个非常古老的庞然大物,使用.htaccess进行大量的redirect。 我可以为这些redirect创build位置块,但我不知道如何将它们应用于该项目(我对nginx不是很熟悉)。
我愿意接受任何可能的解决scheme,我所理论的是:
1)目录特定的nginxconfiguration – 有点像htaccess,但不知道,如果nginx甚至能够在飞行中加载configuration
2)使用if阻止特定的服务器名称,但不能确定的语法,因为我找不到任何例子,如果用于服务器名称
3)单独的虚拟主机为该子域,这将是一个可行的,allthough不是一个非常优雅的解决scheme,我的问题,问题是我不知道如何设置优先级,因为该子域将匹配相同的dynamic虚拟主机模式
任何帮助,或build议或链接非常感激
选项(3)减less了破坏每个子域的风险,只是为了修复一个stream氓子域。 具有完全匹配的server_name server块将始终优先于正则expression式server_name 。 详情请参阅此文件 。
如果你想最小化重复configuration,把通用语句卸载到一个单独的文件中,并使用include语句将其引入。
例如:
server { listen 80; server_name www.theproject.server.company.com theproject.server.company.com; root /var/www/theproject/current/public; # # ... statements to fix "theproject" # include /path/to/common/config; } server { listen 80; server_name ~^(www\.)?(?<sname>.+?).server.company.com$; root /var/www/$sname/current/public; include /path/to/common/config; }