在 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
网友评论