Two ways:
1, location configuration root
server {
listen 80;
server_name ooc.baidu.com;
location /images {
root /opt/files;
}
location / {
try_files $uri $uri/ /index.html;
root /var/www/html/;
autoindex on;
}
location /ooc-dev {
proxy_pass http://120.99.20.11:9898/;
}
location = /50x.html {
root html;
}
}
2, location configuration alias
server {
listen 80;
server_name baidu.com
#charset koi8-r;
#access_log logs/host.access.log main;
location /images {
alias /opt/files;
}
location / {
proxy_pass http://120.99.20.11:8090/;
}
}
When I visit baidu.com/images/a.jpg with the same browser
Using root will map to /opt/files/images/a.jpg
Using alias will directly map /opt/files/a.jpg
Reasonable use of alias and root
After the configuration is complete, restart nginx
./nginx -s reload