nginx进行资源动静分离

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即可
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值