美文网首页
windows下nginx配置静态文件

windows下nginx配置静态文件

作者: 田丰w | 来源:发表于2021-02-04 17:14 被阅读0次

在 nginx.conf 里的配置

  • include 后面的路径是相对于当前配置文件路径的: include conf.d/*.conf;
  • root alias 后面的路径是相对于 nginx.exe 的: root html;
  • error_log access_log pid 后面的路径是相对于 nginx.exe 的: error_log logs/error.log;
  • windows 目录使用单个正斜线(/)作为分隔符(双反斜线也可,nginx会统一解析为单正斜线),盘符用 D: 的形式,路径避免用中文: D:/ngxin/
  • autoindex on; 在 index 能找到的情况下会优先出 index 页面, 没有找到 index 才会出目录

静态目录配置

server {
    listen 8001;
    server_name localhost;

    # root 不会吞掉 location 已经匹配的路径, 如:
    # localhost:8001/html/a -> D:/ngxin/html/a
    location /html {
        root   D:/ngxin;
        index  index.html index.htm;
    }

    # alias  会吞掉 location 已经匹配的路径, 如:
    # localhost:8001/imgs/a.jpg -> D:/ngxin/imgs/a.jpg
    location /imgs/ {
        alias   D:/ngxin/imgs/;
        autoindex on;
        autoindex_exact_size off;
        autoindex_localtime on;
    }
}

windows 下 nginx 目录结构对照

my@wsl$ tree
.
├── conf
│   ├── conf.d
│   │   └── localhost-8001.conf
│   ├── fastcgi.conf
│   ├── fastcgi_params
│   ├── koi-utf
│   ├── koi-win
│   ├── mime.types
│   ├── nginx.conf
│   ├── scgi_params
│   ├── uwsgi_params
│   └── win-utf
├── contrib
│   ├── README
│   ├── geo2nginx.pl
│   ├── unicode2nginx
│   │   ├── koi-utf
│   │   ├── unicode-to-nginx.pl
│   │   └── win-utf
│   └── vim
│       ├── ftdetect
│       │   └── nginx.vim
│       ├── ftplugin
│       │   └── nginx.vim
│       ├── indent
│       │   └── nginx.vim
│       └── syntax
│           └── nginx.vim
├── docs
│   ├── CHANGES
│   ├── CHANGES.ru
│   ├── LICENSE
│   ├── OpenSSL.LICENSE
│   ├── PCRE.LICENCE
│   ├── README
│   └── zlib.LICENSE
├── html
│   ├── 50x.html
│   └── index.html
├── logs
│   ├── access.log
│   ├── error.log
│   └── nginx.pid
├── nginx.exe
└── temp
    ├── client_body_temp
    ├── fastcgi_temp
    ├── proxy_temp
    ├── scgi_temp
    └── uwsgi_temp

参考

https://blog.csdn.net/nrsc272420199/article/details/89368951

相关文章

  • windows下nginx配置静态文件

    在 nginx.conf 里的配置 include 后面的路径是相对于当前配置文件路径的: include co...

  • nginx使用

    Nginx在windows下的安装、运行,以及配置文件讲解 安装Nginx(windows版) 进入Nginx官网...

  • Nginx配置

    nginx配置文件详解 windows上实操可用的配置代码,更改Nginx安装目录下的nginx.conf文件就行

  • Windows环境下Nginx+Lua+Redis实现灰度发布

    Windows环境下Nginx+Lua+Redis实现灰度发布 1.配置nginx.conf文件 2.lua脚本 ...

  • Nginx访问静态资源

    Nginx访问静态资源 即通过IP:端口/文件名 访问文件实现. 修改Nginx配置 重新加载Nginx 上传文件测试

  • nginx图片服务器

    以windows为例1下载nginx文件, 2修改nginx.conf配置文件 修改端口为8083注意以alias...

  • docker运行nginx容器访问静态文件报404错误

    项目运行后,发现前端访问图片报错 flask后台代码 nginx配置文件中,静态文件的配置如下: 重启nginx容...

  • ngnix的简单配置

    ngnix配置代理接口 通过上面的配置就可以实现后端代理接口,前端静态资源的访问 windows下启动停止Nginx服务

  • Docker部署Nginx

    目标: 通docker运行Nginx 通过Nginx容器访问主机的静态资源 通过主机配置文件配置Nginx容器 d...

  • nginx配置静态页面路径

    nginx静态文件路径到底怎么写?!(这路径折腾我一下午) 极度坑人的静态路径配置: location /stat...

网友评论

      本文标题:windows下nginx配置静态文件

      本文链接:https://www.haomeiwen.com/subject/yqgbtltx.html