这是我的映射配置
docker run -p 80:80 --name nginx \
-v /mydata/nginx/html:/usr/share/nginx/html \
-v /mydata/nginx/logs:/var/log/nginx \
-v /mydata/nginx/conf:/etc/nginx \
-d nginx:1.10
很明显我映射出来的nginx地址是:/mydata/nginx/html
docker里面nginx地址是:/usr/share/nginx/html
这是我最初的nginx配置
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location /wx {
alias /mydata/nginx/html/wx/static/html;
index main.html;
}
location /zj {
alias /mydata/nginx/html/wx/static/;
index zhuanji.html;
}
配置后,/wx,/zj怎么修改路径都不生效,root alias都试了好几遍,最后去看了nginx日志,
日志路径:
映射的日志地址: /mydata/nginx/logs
docker里面nginx的日志地址:/var/log/nginx
看的是error日志,
2022/08/27 06:33:37 [error] 7#7: *1 open() "/mydata/nginx/html/wx/static/zhuanji.html" failed (2: No such file or directory)
报错也比较明显,没有找到这个文件和路径,但是我找了下,是有这个文件和路径的,后天突然想到docker里面的nginx是没有这个路径的,所以路径按照docker里面的路径地址改了下,配置如下
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location /wx {
alias /usr/share/nginx/html/wx/static/html;
index main.html;
}
location /zj {
alias /usr/share/nginx/html/wx/static/;
index zhuanji.html;
}
之后就成功了