nginx重复位置“/”错误

时间:2014-06-15 10:27:17

标签: nginx

当scheme为http且location为/

时,我想重定向到https
server {
    listen          80;
    server_name     bla;

    location / {
        return 301 https://bla;
    }

    include fs.inc;
}

现在,问题是:fs.inc包括anothes“location /”,即使从未调用过nginx配置测试也会失败并显示错误duplicate location "/" in fs.inc:1

我该如何解决?

1 个答案:

答案 0 :(得分:0)

您需要另一个服务器块:

server {
    listen 443;
    server_name bla; # make sure this is the same

    # add your ssl specific directives here

    location / {
        alias /var/www/secured/;
    }
}

server {
    listen 80;
    server_name bla;

    return 301 https://$request_uri;
}

这是全局重定向