Nginx部署靜態頁面及引用圖片有效訪問的兩種方式

nginx安裝百度一下有不少,直接正題:css

靜態文件目錄結構html

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

  cssserver

  jshtm

  images圖片

  htmlio

  fonts百度

配置nginx.conf核心代碼(html引用圖片用的是相對路徑)配置

第一種:實用型file

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

相關文章
相關標籤/搜索