zoukankan      html  css  js  c++  java
  • docker 安装 nginx

    1.首先拉取nginx
    2.先运行nginx,将容器内的/etc/nginx/nginx.conf拷贝出来
    3.重新编辑nginx.conf,放入本地路径
    4.停止nginx,删除容器,然后重新运行容器,挂载配置自己编辑的配置文件

    #拉取最新版本nginx
    docker pull nginx
    
    #查看拉取的镜像
    docker images
    
    #运行nginx镜像
    docker run -itd -p 8080:80 --name nginxTest nginx
    
    #拷贝nginxTest容器配置文件到本地机器
    docker cp nginxTest:/etc/nginx/nginx.conf /nginx.conf
    
    

    nginx.conf配置

    #源配置文件
    user  nginx;
    worker_processes  auto;
    
    #日志文件 不加/ 表示相对位置相对当前文件 加/ 绝对路径
    #当path/file 的值为 /dev/null时,这样就不会输出任何日志了,这也是关闭error日志的唯一手段;
    #leve的取值范围是debug、info、notice、warn、error、crit、alert、emerg从左至右级别依次增大。
    error_log  /var/log/nginx/error.log notice;
    pid        /var/run/nginx.pid;
    
    
    events {
        worker_connections  1024;
    }
    
    http {
        #导入mime.types文件
        include       /etc/nginx/mime.types;
        default_type  application/octet-stream;
    
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
    
        access_log  /var/log/nginx/access.log  main;
    
        sendfile        on;
        #tcp_nopush     on;
    
        keepalive_timeout  65;
    
        #gzip  on;
        #导入*.conf文件
        include /etc/nginx/conf.d/*.conf;
    }
    
    

    修改为自己的配置文件按

    
    worker_processes  1;
    #日志文件/log/error.log
    error_log  /log/error.log error;
    
    events {
        worker_connections  1024;
    }
    
    
    http {
    
        include       /etc/nginx/mime.types;
        default_type  application/octet-stream;
    
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
    
        sendfile        on;
    
        keepalive_timeout  65;
    
        server {
            listen       80;
            server_name  localhost;
    
    
            location / {
                #项目访问路径 /html/sealHome 在这个文件夹下要有iddex.html
                root   /html/sealHome;
                index  index.html;
            }
    
            location = /50x.html {
                root   html;
            }
        }
    
        server {
            listen       8085;
            server_name  localhost;
    
            location / {
                #项目访问路径 /html/sealHome 在这个文件夹下要有iddex.html
                root   /html/sealAdmin;
                index  index.html;
            }
    
            location = /50x.html {
                root   html;
            }
        }
    
    
    }
    
    

    5.配置完成之后 停止刚才的容器,删除容器,重新部署自己的项目

    #查看容器
    docker ps
    
    #停止容器
    docker stop nginxTest
    
    #删除容器
    docker rm nginxTest
    
    #启动容器 重命名 端口映射 配置文件挂载 项目位置挂载 日志文件挂载 重启自启
    docker run -itd --name myNginx -p 8080:80 -p 8085:8085 -v /nginx.conf:/etc/nginx/nginx.conf -v /usr/local/docker/nginx/html:/html -v /usr/local/docker/nginx/log:/log --restart always nginx
    
    
  • 相关阅读:
    超经典~超全的jQuery插件大全
    如何用PHP做到页面注册审核
    php实现签到功能
    php中的实用分页类
    微信小程序,超能装的实例教程
    php之 常用的 流程管理
    php之 人员的权限管理(RBAC)
    php之简单的文件管理(基本功能)
    php最新学习-----文件的操作
    关于LAMP的配置之(虚拟机的安装、创建、配置)
  • 原文地址:https://www.cnblogs.com/lvshichao/p/15049924.html
Copyright © 2011-2022 走看看