Nginx部署静态页面及引用图片有效访问的两种方式


nginx安装百度一下有很多,直接正题:

静态文件目录结构

file#文件位置 /home/service/file/

  css

  js

  images

  html

  fonts

配置nginx.conf核心代码(html引用图片用的是相对路径)

第一种:实用型

server {
listen 80;
server_name localhost;

location ^~/image{
   root /home/;#图片路径
}

location / {
  root /home/service/file/html;
  index home.html;
}

第二种:简单易懂

server {
listen 80;
server_name localhost;

location / {
  root /home/service/file/;#执行HTML和image的父级路径
  index  html/home.html;
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM