Redirect Nginx:仅在位置匹配时使用服务器块
我有一个如下所示的全面服务器块:Redirect Nginx:仅在位置匹配时使用服务器块,redirect,nginx,Redirect,Nginx,我有一个如下所示的全面服务器块: server { listen 80 default_server; server_name _; location /blog{ # pass request to ghost } location /{ # pass request to custom node app } } 它传递到自定义节点应用程序,该应用程序验证请求的域、协议和路径,并在必要时发出单个301
server {
listen 80 default_server;
server_name _;
location /blog{
# pass request to ghost
}
location /{
# pass request to custom node app
}
}
它传递到自定义节点应用程序,该应用程序验证请求的域、协议和路径,并在必要时发出单个301重定向;我们这样做是为了最小化301重定向,用于SEO目的
我还需要我的鬼博客只提供在。我添加了以下块:
server {
listen 80;
server_name example.com;
location /blog {
return 301 https://www.example.com$request_uri;
}
}
这样,对裸域的请求将被重定向。但是现在请求example.com返回默认的Nginx index.html页面。我如何防止这种情况?我希望避免使用
,如果
您需要在裸域服务器块中有一个通配符来路由到节点应用程序
server {
listen 80;
server_name example.com;
location /blog {
return 301 https://www.example.com$request_uri;
}
location /{
# pass request to custom node app
}
}
那么,您是否要重定向两个不同的/博客位置?为什么不将catch all位置添加到example.com服务器块中?我仍然需要裸域上的所有非/blog请求才能转到我的自定义节点应用程序。问题是第二个服务器块阻止了这种情况的发生。所以只需复制整个
位置/
块?是的,问题是裸域仅指定在位置为/blog时要执行的操作。所以设置catchall应该可以让你工作。