我试图将所有没有服务器指令的托pipe域redirect到位于公司域服务器指令内的停放页面。
目前,我有以下的只能redirect到主页,因为转发NON-TLS公司域请求也需要相同的指令。
server { listen 80 default_server; listen [::]:80 default_server; server_name _; return 301 https://company.com$request_uri; }
我需要一个服务器指令,将所有不是company.com的请求转发到company.com/parked.php
您可以使用以下configuration:
server { listen 80; listen [::]:80; server_name company.com; return 301 https://company.com$request_uri; } server { listen 80 default_server; listen [::]:80 default_server; server_name _; return 301 https://company.com/parked.php; }
因此,您为处理http – > httpsredirect的company.com域指定一个虚拟主机,并指定一个redirect到停放页面的默认服务器。 这比使用if指令更高效一些。
你可能想要这样的东西:
if ( $host != 'company.com' ) { return 301 https://company.com/parked.php }
注意:如果在nginx中被认为是邪恶的( https://www.nginx.com/resources/wiki/start/topics/depth/ifisevil/ ),但这是less数几个安全使用它的方法之一。