Nginx 静态资源访问

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_37657245/article/details/78763782
首先说下目录访问的问题:
1、首先访问的目录路径中权限设置要没问题
2、autoindex默认是关闭的
3、要告诉nginx是一个目录而不是文件,这个地方非常值得注意,若想访问目录,URL最后一个字符得是‘/'。
```
location =/test{
    root /tmp/html/www;
    autoindex on;
}
```
本意是想访问/tmp/html/www/下的test目录,但是因为‘/test’会让nginx误以为这是一个名为test的文件。
我们在这里必须改为'/test/'。

在url的匹配中人们很常使用

```
location ~ ^/test{
    root /tmp/html/www;
    autoindex on;
}
```
这里是匹配到url开头有‘/test’就能匹配上。所以我觉得我写的这个问题可能有点low,但很值得注意。

猜你喜欢

转载自blog.csdn.net/weixin_37657245/article/details/78763782