注意:nginx的挂载比较特殊:
需要先运行起来,然后把容器内的配置文件拷贝到当前的目录,关闭并移除nginx,重新运行并挂载目录文件。
1.运行nginx,没有则自动下载
docker run -p 8090:80 --name nginx -d nginx
2.将容器内的配置文件拷贝到当前目录:
docker container cp nginx:/etc/nginx .
3.修改nginx 名称为conf,并创建新的nginx文件
mv nginx conf
4.移动conf到nginx/ 目录
mv conf nginx/
5.重新运行nginx
docker run -p 8090:80 --name nginx -v ~/mydata/nginx/html:/usr/share/nginx/html -v ~/mydata/nginx/conf:/etc/nginx -v ~/mydata/nginx/logs:/var/log/nginx -d nginx
1.在html文件夹下创建 index.html
文件,注意一是 index.html
文件。因为default.conf文件下配置的为index.html,若要改成a.html则需要修改文件并重启nginx服务。
2.写上内容,并打开浏览器访问 http://localhost:8090/
进行测试。
https://blog.csdn.net/weixin_35688029/article/details/81773300
1.首先在nginx.conf文件的http中添加:
upstream myserver{
server 本机ip:8080 weight=1;
server 本机ip:8081 weight=1;
}
2.在location中添加:
location / {
proxy_pass http://myserver;
}
3.Nginx中文网站
https://www.nginx.cn/doc/example/loadbanlance.html
原文:https://www.cnblogs.com/xxs-oao/p/15096767.html