反向代理配置 - 文件夹重定向到原始 url
Reverse Proxy Configuration - Folder redirecting to original url
我最近为我们的客户创建了一个反向代理设置,基本上,我们是一个服务提供商,由于我们的工具而托管静态 HTML 文件。
现在客户希望他们的用户可以通过一种简单的方式访问内容并从 SEO 中受益,因此我们选择了反向代理方法。
客户端看起来像 https://clientdomain.com/mycontent
我们的域名是:https://staticfiles.com
当我们写 https://clientdomain.com/mycontent/foldername/ 时,我们的服务器正确地提供来自服务器的 index.html 文件,客户端很高兴。
但是当我们尝试访问 https://clientdomain.com/mycontent/foldername (without slash), our server gives a 301 response and redirects users to https://staticfiles.com/foldername/(带斜杠)
时,问题就出现了
通过 Nginx 配置处理此问题的任何方式,在重定向到文件夹符号之前,它会检查传入主机,然后相应地重定向它。
对于代理传递,我们使用以下配置:
location /mycontent {
proxy_pass https://staticfiles.com/;
proxy_redirect redirect replacement;
}
在这个代码片段中,当我们试图详细阅读 nginx 文档时,我们发现它并不是字面上的意思,而是必须在此处提供重定向 URL
proxy_redirect redirect replacement;
所以这实际上应该是
proxy_redirect https://staticfiles.com https://clientdomain.com/mycontent
这将做的是更改从实际服务器收到的任何位置 headers https://staticfiles.com to https://clientdomain.com/mycontent 的所有实例。
我最近为我们的客户创建了一个反向代理设置,基本上,我们是一个服务提供商,由于我们的工具而托管静态 HTML 文件。 现在客户希望他们的用户可以通过一种简单的方式访问内容并从 SEO 中受益,因此我们选择了反向代理方法。
客户端看起来像 https://clientdomain.com/mycontent
我们的域名是:https://staticfiles.com
当我们写 https://clientdomain.com/mycontent/foldername/ 时,我们的服务器正确地提供来自服务器的 index.html 文件,客户端很高兴。
但是当我们尝试访问 https://clientdomain.com/mycontent/foldername (without slash), our server gives a 301 response and redirects users to https://staticfiles.com/foldername/(带斜杠)
时,问题就出现了通过 Nginx 配置处理此问题的任何方式,在重定向到文件夹符号之前,它会检查传入主机,然后相应地重定向它。
对于代理传递,我们使用以下配置:
location /mycontent {
proxy_pass https://staticfiles.com/;
proxy_redirect redirect replacement;
}
在这个代码片段中,当我们试图详细阅读 nginx 文档时,我们发现它并不是字面上的意思,而是必须在此处提供重定向 URL
proxy_redirect redirect replacement;
所以这实际上应该是
proxy_redirect https://staticfiles.com https://clientdomain.com/mycontent
这将做的是更改从实际服务器收到的任何位置 headers https://staticfiles.com to https://clientdomain.com/mycontent 的所有实例。