正常打开单个静态资源
location
块中静态资源路径配置使用 root
server {
listen 10010;
server_name localhost;
location /test01 {
root /home/test01;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
配置不同前缀打开不同静态资源
location
块中静态资源路径配置改为alias
, 不用 root
- 前缀使用单
/
: /test01
, 不用双/
: /test01/
server {
listen 10010;
server_name localhost;
location /test01 {
alias /home/test01;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location /test02 {
alias /home/test02;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}