小编use*_*667的帖子

nginx 重定向循环,index.html

这看起来很荒谬,但我在一个多小时的搜索中没有找到有效的答案。当我访问“ http://oa.wechat.com/screen/index.html ”时,它会导致一个301重定向循环,如下所示:

"GET /screen/ HTTP/1.1" 301
"GET /screen/index.html/ HTTP/1.1" 301 
"GET /screen/index.html/index.html/ HTTP/1.1" 301 
... 
Run Code Online (Sandbox Code Playgroud)

nginx 版本:1.5.6 nginx.conf

    server {
        listen  80;
        server_name oa.wechat.com;

        location ~ ^/screen/ {
            alias /data/screen/static/;
            index index.html;
        }  
    } 
Run Code Online (Sandbox Code Playgroud)

谁能告诉我原因?非常感谢。

我已经检查了 nginx 文档。“别名”的正确用法:

    # use normal match like this
    location  /i/ {
      alias  /spool/w3/images/;
    }

    # use regex match like this
    location ~ ^/download/(.*)$ {
      alias /home/website/files/$1;
    }
Run Code Online (Sandbox Code Playgroud)

使用“别名”的错误方法是:

    location ~ ^/screen/ {
        alias /data/screen/static/;
        index index.html;
    }  
Run Code Online (Sandbox Code Playgroud)

在这种情况下,请求将被视为目录请求,而不是文件请求,这将导致重定向循环。

无论如何,非常感谢肉!

nginx

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

标签 统计

nginx ×1