1.首先创建一个nginx的新文件夹以存储静态资源
[root@localhost ~]# cd /mydata/nginx/html
[root@localhost html]# mkdir static
[root@localhost html]# ls
es index.html static
[root@localhost html]# cd static
2.我是通过xshell和xftp以从windows访问linux,这里就使用了xftp将静态资源上传到了static文件夹内。然后就可以将项目内的静态资源删除了。
3.修改html中的资源访问路径
直接进行替换:href="替换成href="/static/,<script src="替换成<script src="/static/,<img src="替换成<img src="/static/,src="index/js替换成src="/static/index/js,然后重启项目
4.在相应的nginx的配置文件xxx.conf下加入以下内容
找到conf文件
[root@localhost static]# cd /mydata/nginx/conf/conf.d
[root@localhost conf.d]# ls
default.conf gulimall.conf
添加内容:
#这句话的意思是凡是有static的都会走下面的root路径
location /static/ {
root /usr/share/nginx/html;
}
重启nginx:docker restart nginx即可