server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#正则表达式匹配
location ~ test {
root C:/Users/Susan/Desktop;
#Nginx默认是不允许列出整个目录的
#开启目录浏览功能
autoindex on;
}
我的文件目录结构
访问路径localhost/test 访问成功
我的打开test/default.htm 会跳转到test/web/index.htm
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#普通匹配规则
location /test/ {
root C:/Users/Susan/Desktop;
index default.htm
autoindex on;
}
访问路径http://localhost/test/default.htm
访问成功
测试时,注意清理页面缓存,autoindex on;打开目录浏览功能才能访问到文件夹下的资源
新手上路,不足之处请在评论多多指正。