一步到位在nginx配置图片服务器

6,068 阅读1分钟

查看nginx配置文件

输入指令

nginx -t

nginx配置文件位置如下

编辑配置文件

  1. 输入指令
vim /etc/nginx/nginx.conf
  1. 增加访问规则

找到server,在sever对象下建立新的规则

意思是:当我们访问域名下的images,nginx会找到web目录下的images文件夹

location ^~ /images/ {
      alias /web/images/;
      index index.htm index.html;
      autoindex on;
      # expires 10d;
      # add_header Cache-Control max-age=3600000;
}
  1. 保存
:wq

传入图片

这里通过xftp上传图片的,上传完之后

通过https://你的域名/images/图片.png,就可以访问图片了

配置第多文件夹图片访问

图片存放文件夹为web下面的another_images文件夹

location ^~ /another-images/ { 
      alias /web/another_images/;
      index index.htm index.html;
      autoindex on;
      #expires 10d;
      #add_header Cache-Control max-age=3600000;
}

通过https://你的域名/another-images/图片.png,就可以访问图片了