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;
}
【推荐】2025 HarmonyOS 鸿蒙创新赛正式启动,百万大奖等你挑战
【推荐】博客园的心动:当一群程序员决定开源共建一个真诚相亲平台
【推荐】开源 Linux 服务器运维管理面板 1Panel V2 版本正式发布
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步