小编use*_*306的帖子

Nginx:将 https:// 重写为 http://

我试图让Nginx的传入请求改写到一个网站我的服务器前缀https://http://(这是因为CMS上这个网站的URI的力量,而不是相对路径使用服务-利用图片,脚本和样式表基本上打破了整个网站不可用)。

我目前正在尝试改造由前任制定的现有指令,但我发现自己受限于我对 Nginx 配置语法的了解。这是代码:

if ($ssl_protocol = "") {
    rewrite ^   https://$http_host$request_uri? permanent;
}
Run Code Online (Sandbox Code Playgroud)

我目前已将此代码注释掉以防止强制重写http://to https://,但我无法在不破坏站点的情况下逆转该过程。这是我迄今为止尝试过的:

if ($ssl_protocol = "https") {
    rewrite ^   http://$http_host$request_uri? permanent;
}
Run Code Online (Sandbox Code Playgroud)

# also tried ($ssl_protocol != "")
if (!($ssl_protocol = "")) {
    rewrite ^   http://$http_host$request_uri? permanent;
}
Run Code Online (Sandbox Code Playgroud)

第一个似乎没有影响。发送到客户端的 HTML 仍然会发出未被重写的 HTTPS 请求。

第二个片段似乎也没有任何影响 - 如果我理解正确(尽管我仍然有些惊讶),Nginx 不支持布尔否定。

这样做的最佳方式(或工作方式)是什么?

编辑:我尝试从@NathanC 的答案中添加代码;但是,这种无条件重写会导致重定向循环。仍然感谢帮助。

rewrite nginx

5
推荐指数
1
解决办法
3万
查看次数

标签 统计

nginx ×1

rewrite ×1