错误:网页有重定向循环

错误:网页有重定向循环

我当前的设置如下:

server {
listen 80; 
listen 443; 

root /usr/share/nginx/www;
index index.html index.htm;

server_name localhost;

location / {
    try_files $uri $uri/ /index.html;
}

location /doc/ {
    alias /usr/share/doc/;
    autoindex on;
    allow 127.0.0.1;
    deny all;
}

error_page 404 /404.html;
if ($scheme = http) {
    return 301 https://$server_name$request_uri;
}
}

有任何想法吗?

答案1

正如 AD7six 提到的,使用两个server这样的块:

server {
    listen 80;
    server_name localhost;

    rewrite 301 https://$server_name$request_uri$is_args$args;
}

server {
    listen 443;
    server_name localhost;

    root /usr/share/nginx/www;
    index index.html index.htm;

    location / {
        try_files $uri $uri/ /index.html;
    }

    location /doc/ {
        alias /usr/share/doc;
        autoindex on;
        allow 127.0.0.1;
        deny all;
    }

    error_page 404 /404.html;
}

相关内容