小编cme*_*one的帖子

在 Nginx 服务器上强制使用 SSL 时重定向循环

最近我一直在尝试使用 Nginx 重定向到 HTTPS,但是在我尝试在浏览器中访问我的网站后,我不断收到重定向循环。这是我的完整服务器块配置文件:

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;
    listen 443 ssl;

    root /var/www;
    index index.php index.html index.htm home.html contact.html projects.html;

    # Make site accessible from http://localhost/
    server_name melone.co;
    return 301  https://$host$request_uri;
    ssl_certificate /path/to/ssl;
    ssl_certificate_key /path/to/ssl;


    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
        proxy_set_header        X-Forwarded-Proto $scheme;
    }
    error_page 404 /404.html;

        # redirect server error pages to the …
Run Code Online (Sandbox Code Playgroud)

ssl nginx https tls 301-redirect

2
推荐指数
1
解决办法
4655
查看次数

标签 统计

301-redirect ×1

https ×1

nginx ×1

ssl ×1

tls ×1