在Nginx中重定向两个长域URLS的最佳方法是什么,我想在两个域之间配置一个重定向,如下所示:
我相信这之前有人问过,但我找不到一个可行的解决方案。
原始链接:
https://qwerty.test.com/education/7/abc-science
新链接
https://www.test.com/education/7/abc-science
我们使用alb作为http到https。
我试过这样做:
server {
listen 80;
listen 443 ssl;
server_name qwerty.test.com/education/7/abc-scienc;
return 301 $scheme://www.test.com/education/7/abc-science$request_uri;
}我的输出
curl -I qwerty.test.com/education/7/abc-scienc
HTTP/1.1 301 Moved Permanently
Location: https://qwerty.test.com/education/7/abc-scienc仍然会收到一些错误
nginx: [warn] server name "education/7/abc-scienc
" has suspicious symbols in /etc/nginx/conf.d/redirect.conf:9
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful我是否需要用这种方式将原来的URL重定向到new?
location = /content/unique-page-name {
return 301 /new-name/unique-page-name;
}有人能帮我吗?这里怎么了?
任何帮助都是非常感谢的!谢谢!
发布于 2022-10-17 18:37:39
这实际上是正确的。Nginx正在返回301 Moved Permanently,这正是您想要的。如果您希望curl实际上遵循重定向,则需要添加-L。
curl -L qwerty.test.com/education/7/abc-scienc来自curl文档的解释:
-L,--location (HTTP/HTTPS)如果服务器报告请求的页面已移动到不同的位置(用位置:头和3XX响应代码指示),则此选项将使请求在新位置上重新执行。如果与-I一起使用,--包括或-i,-头,将显示来自所有请求页面的标题。当使用身份验证时,curl只将其凭据发送到初始主机。如果重定向将卷曲转到另一个主机,它将无法拦截user+password。也见--位置-关于如何改变这一点的信任。您可以使用--max-redirs选项来限制重定向的数量。
当curl遵循重定向,并且请求不是普通的GET (例如POST或PUT)时,如果HTTP响应为301、302或303,它将使用GET执行以下请求。如果响应代码是任何其他3xx代码,curl将使用相同的未修改方法重新发送以下请求.
https://stackoverflow.com/questions/74101316
复制相似问题