023--Docker使用nginx

2020-02-02  本文已影响0人  糖纸疯了

参考网址:https://www.cnblogs.com/pangziyibudong/p/6211921.html
参考网址:https://blog.csdn.net/u011164906/article/details/73135836?locationNum=5&fps=1
参考网址:https://www.jianshu.com/p/6b317192480c

1、使用nginx进行简单负载

1、先运行nginx
    docker run -d --name nginx nginx
2、进入运行的nginx,将nginx的配置保存到指定的目录
    docker container ls     (查看nginx的containerID)
    export NGINX_PATH=/apps/config/nginx
    mkdir -p $NGINX_PATH/conf       (创建自己的nginx配置目录)
    mkdir -p $NGINX_PATH/html       
    #mkdir -p $NGINX_PATH/conf/nginx.conf
    docker cp d604c2f51ba3:/etc/nginx/nginx.conf $NGINX_PATH/conf
    如果不更改,访问403权限拒绝
    chmod -R 755 $NGINX_PATH
    
3、停止nginx镜像(运行的目的是拷贝nginx配置信息)
    docker container stop f595969572d3
    docker container rm f595969572d3
    
4、修改相关的本地配置
    vim $NGINX_PATH/conf/nginx
    
5、添加主页展示页面
    echo "hello">$NGINX_PATH/html/index.html

5、运行挂载我们自己的配置文件
    
docker run -d -p 8081:80 --name nginx-web -v $NGINX_PATH/html:/usr/share/nginx/html -v $NGINX_PATH/conf/nginx.conf:/etc/nginx/nginx.conf -v $NGINX_PATH/logs:/var/log/nginx nginx
上一篇 下一篇

猜你喜欢

热点阅读