这是 nginx_conf 文件中的服务器块:
我正在使用 cloud66,因此我可以从我的仪表板编辑它。
这总是出错。我怀疑这是因为我的条件和 if 语句。
我正在尝试将以下 URL 重新路由到以下 URL:
http://subdomain.domain.com/notes.php并将其路由到 /dashboard 并将其路由到 http://domain.com/dashboard
http://subdomain.domain.com/contact-us.php并将其路由到 /dashboard 并将其路由到 http://domain.com/contact-us/new
http://subdomain.domain.com/help.php并将其路由到 /dashboard 并将其路由到 http://domain.com/faq
server
{
...
# redirect old routes on subdomain
server_name ~^www\.(?<domain>.+)$;
if ($host ~ "^(.*)$domain") {
set $subd $1;
if $1 = 'notes.php'{
rewrite ^(.*) /dashboard permanent;
}
if $1 = 'contact-us.php'{
rewrite ^(.*) /contact-us/new permanent;
}
if $1 = 'help.php'{
rewrite ^(.*) /faq permanent;
}
}
}
当我放置这个时出现以下错误:
+ server
+ {
+ server_name secure.inrtracker.com www.secure.inrtracker.com;
+
+ location = /notes.php {
+ rewrite ^ /dashboard permanent;
+ }
+ }
发生错误。抱歉,您查找的页面目前不可用。请稍后重试。如果您是此资源的系统管理员,则应检查错误日志以了解详细信息。谨致问候,nginx。
答案1
首先:必须如果是邪恶的
其次,你应该将子域名和域名分离到不同的服务器块(和/或不同的文件)。然后创建重写规则
server {
server_name oursubdomain.domain.com www.oursubdomain.domain.com;
location / {
rewrite ^/notes.php$ $scheme://domain.com/dashboard permanent;
rewrite ^/contact-us.php$ $scheme://domain.com/contact-us/new permanent;
rewrite ^/help.php$ $scheme://domain.com/faq permanent;
}
}
server {
server_name domain.com www.domain.com;
location = /dashboard {
# Do something here, possibly send to php
}
location = /faq {
# Do something here, possibly send to php
}
location = /contact-us/new {
# Do something here, possibly send to php
}
}
我希望这能对你有帮助!