windows下nginx配置静态文件

在 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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容