问题描述
配置好文件共享目录后,访问根目录不带/如,http://ip/share时,会自动跳转到http://ip/share/。但当nginx服务端口映射到公网端口如999,且公网地址端口与nginx服务端口80不一致时,使用公网地址如http://公网ip:999/share访问,nginx则会301重定向到http://公网ip/share导致访问异常。
解决方案:
对share路径重写
if ($request_uri = "/share") {
rewrite ^/(.*)$ $scheme://$http_host/$1/ permanent;
}
# file share
location /share {
auth_basic "Login";
auth_basic_user_file /etc/nginx/conf.d/auth;
alias /root; #指定实际目录绝对路径;
autoindex on; # 开启目录浏览功能;
autoindex_exact_size off; #关闭详细文件大小统计,让文件大小显示MB,GB单位,默认为b;
autoindex_localtime on; #开启以服务器本地时区显示文件修改日期!
charset utf8;
}