Skip to content

[Feature] Optimize HTTP to HTTPS redirection configuration #11410

@Trashblazer

Description

@Trashblazer

1Panel Version

2.0.15

Please describe your needs or suggestions for improvements

1Panel在nginx的 443 端口的 server 语句块中用

if ($scheme = http) {
    return 301 https://$host$request_uri;
}

判断协议为http则跳转https站点。

该方法逻辑简单直观,但不推荐。理由是处理请求时都会多一次if判断。

更简洁的办法是直接在 80 端口的 server 块中使用 return 301(无需 if),这是 Nginx 官方推荐的方式,性能更高且更稳定:

server {
    listen 80;
    server_name yourdomain.com www.yourdomain.com;
    return 301 https://$host$request_uri;  # 无 if,直接跳转
}

Please describe the solution you suggest

No response

Additional Information

No response

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions