前后端分离后,把前端页面放入nginx中,在nginx配置如下:
location /vue/office/ {
alias html/vue/office/;
index index.html;
autoindex on;
}
使用nginx 配置静态资源遇到个坑 可能思维方式不一样
假设我要访问的地址是:127.0.0.1/images/tmp.jpg
静态资源地址是:/usr/local/static/images/tmp.jpg
正确的配置:
//root配置
//127.0.0.1/images/tmp.jpg = /usr/local/static/images/tmp.jpg
location /images/ {
root /usr/local/static/
}
//alias配置
//127.0.0.1/images/tmp.jpg = /usr/local/static/images/tmp.jpg
location /images/ {
alias /usr/local/static/images/
}
错误的配置:
//root配置
//127.0.0.1/images/tmp.jpg = /usr/local/static/images/images/tmp.jpg
location /images/ {
root /usr/local/static/images/
}
//alias配置
//127.0.0.1/images/tmp.jpg = /usr/local/static/tmp.jpg
location /images/ {
alias /usr/local/static/
}
原因
root配置 root后面地址+location 后面地址
alias配置 就是root配置的地址
alias配置最后一定要 “/” 结尾 root配置随意