• docker安装nginx并挂载目录


    第一步 利用docker拉取nginx镜像

    docker pull nginx

    第二步 创建需要挂载的相应的挂载目录

    mkdir -p nginx/conf
    
    mkdir -p nginx/html
    
    mkdir -p nginx/logs

    第三步 创建nginx.conf文件(这里我用的是官方默认的配置文件,可以替换成自己的配置文件,nginx的版本是1.14.2)

    #user  nobody;
    worker_processes  1;
    
    #error_log  logs/error.log;
    #error_log  logs/error.log  notice;
    #error_log  logs/error.log  info;
    
    #pid        logs/nginx.pid;
    
    
    events {
        worker_connections  1024;
    }
    
    
    http {
        include       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  logs/access.log  main;
    
        sendfile        on;
        #tcp_nopush     on;
    
        #keepalive_timeout  0;
        keepalive_timeout  65;
    
        #gzip  on;
    
        server {
            listen       80;
            server_name  localhost;
    
            #charset koi8-r;
    
            #access_log  logs/host.access.log  main;
    
            location / {
                root   html;
                index  index.html index.htm;
            }
    
            #error_page  404              /404.html;
    
            # redirect server error pages to the static page /50x.html
            #
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
    
            # proxy the PHP scripts to Apache listening on 127.0.0.1:80
            #
            #location ~ .php$ {
            #    proxy_pass   http://127.0.0.1;
            #}
    
            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
            #location ~ .php$ {
            #    root           html;
            #    fastcgi_pass   127.0.0.1:9000;
            #    fastcgi_index  index.php;
            #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            #    include        fastcgi_params;
            #}
    
            # deny access to .htaccess files, if Apache's document root
            # concurs with nginx's one
            #
            #location ~ /.ht {
            #    deny  all;
            #}
        }
    
    
        # another virtual host using mix of IP-, name-, and port-based configuration
        #
        #server {
        #    listen       8000;
        #    listen       somename:8080;
        #    server_name  somename  alias  another.alias;
    
        #    location / {
        #        root   html;
        #        index  index.html index.htm;
        #    }
        #}
    
    
        # HTTPS server
        #
        #server {
        #    listen       443 ssl;
        #    server_name  localhost;
    
        #    ssl_certificate      cert.pem;
        #    ssl_certificate_key  cert.key;
    
        #    ssl_session_cache    shared:SSL:1m;
        #    ssl_session_timeout  5m;
    
        #    ssl_ciphers  HIGH:!aNULL:!MD5;
        #    ssl_prefer_server_ciphers  on;
    
        #    location / {
        #        root   html;
        #        index  index.html index.htm;
        #    }
        #}
    
    }

    第四步 进入到nginx文件夹

    cd nginx/

    第五步 获取docker 镜像中nginx的文件路径(这里是我提前找好的,可以直接套用。如果想要自己尝试去寻找,可以先将镜像启动后,通过docker exec -it nginx bash命令进入到容器内部自己寻找)

    html文件路径: /etc/nginx/html
    配置文件路径:/etc/nginx/nginx.conf
    日志存放路径:/var/log/nginx

    第六步 运行docker run命令启动容器 并将文件挂载出来

    docker run --name nginx -d -p 80:80 -v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf -v $PWD/html:/etc/nginx/html -v $PWD/logs:/var/log/nginx nginx

    完成!!!

  • 相关阅读:
    Cookie与session
    orm之中介模型
    mysql数据库基础命令——幕布链接
    css——幕布链接
    HTML基础——幕布链接
    js基础——幕布
    三层结构与MVC
    [C++]3-1 得分(Score ACM-ICPC Seoul 2005,UVa1585)
    [C++]环状序列(CircularSequence,ACM/ICPC Seoul 2004,UVa1584)
    [C++]猜数字游戏的提示(Master-Mind Hints,UVa340)
  • 原文地址:https://www.cnblogs.com/Mateo-dengmin/p/12018204.html
Copyright © 2020-2023  润新知