码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2019-05-01 12:13:21      阅读:1395      评论:0      收藏:0      [点我收藏+]

标签:直接   静态文件   配置   home   nginx安装   执行   代码   oca   lis   

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部署静态页面及引用图片有效访问的两种方式

标签:直接   静态文件   配置   home   nginx安装   执行   代码   oca   lis   

原文地址:https://www.cnblogs.com/java-01/p/10799436.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!