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;
}

猜你喜欢

转载自www.cnblogs.com/java-01/p/10799436.html