zoukankan      html  css  js  c++  java
  • docker 配置nginx

    0.主要目录位置

    代码目录文件夹:   /usr/share/nginx/html

    配置文件:/etc/nginx/conf.d

    1 准备宿主机目录

    cd /
    mkdir myweb
    
    cd myweb
    mkdir html nginx
    cd nginx
    mkdir conf.d
    

    创建index.html

    <html>
    <body>
        <h1>my docker</h1>
    </body>
    </html>

    2 试运行容器(没有数据卷)

    docker run -p 8080:80  -d nginx
    exec 678ab0b7bbfe ls /etc/nginx/conf.d

    找到这个default.conf文件

    server {
        listen       80;
        listen  [::]:80;
        server_name  localhost;
    
        #charset koi8-r;
        #access_log  /var/log/nginx/host.access.log  main;
    
        location / {
            root   /usr/share/nginx/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   /usr/share/nginx/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;
        #}
    }
    View Code
    docker cp 678ab0b7bbfe:/etc/nginx/conf.d/default.conf /myweb/nginx/conf.d

    把这个配置文件复制出来,然后把这个容器删了

    docker rm -f 678ab0b7bbfe

    3 重新运行容器(有数据卷)

    docker run -p 8080:80 -v /myweb/html:/usr/share/nginx/html -v /myweb/nginx/conf.d:/etc/nginx/conf.d -v /myweb/log:/var/log/nginx  --name my_nginx_test -d nginx
    

    docker run -p 8080:80

    -v /myweb/html:/usr/share/nginx/html

    -v /myweb/nginx/conf.d:/etc/nginx/conf.d

    -v /myweb/log:/var/log/nginx

    --name my_nginx_test -d nginx

    4 运行成功验证

  • 相关阅读:
    mysql数据库表中判断字段是否存在,如果不存在则创建该字段
    PHP同时操作两个mysql数据库
    Bootstrap-分页插件Paginator
    NLP--自然语言处理与机器学习会议
    对CURL的一些研究
    Nginx完整配置说明
    SecureCRT自动登陆到服务器的脚本以及脚本编写简单说明
    Fast CGI 工作原理
    FastCGI中文规范
    Linux +apache+fastcgi运行c/c++
  • 原文地址:https://www.cnblogs.com/polax/p/14418598.html
Copyright © 2011-2022 走看看