server {
listen 80;
server_name localhost;
location /api/ {
# 访问的目录为 root + location
root html;
# 要么使用alias html/api/
index index.html index.htm;
}
location / {
root html;
index index.html index.htm;
}
location /download/ {
root html;
# autoindex on;
}
error_page 404 /404.html;
}
1.同个域名:端口下,不同location的写法
2.root 指的是最终文件目录的上一级目录地址,alias 指的就是最终文件目录的地址
文件目录如下
~/html
|-/api
|-/res
如果要访问 localhost:port/api 的话
location就需要这样写
location /api/ {
root html;
}
或者
location /api/{
alias html/api
}