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