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

Posted java-01

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;
}

 

以上是关于Nginx部署静态页面及引用图片有效访问的两种方式的主要内容,如果未能解决你的问题,请参考以下文章