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 运行成功验证

  • 相关阅读:
    POJ1064 浮点数二分答案
    2019牛客暑期多校训练营(第二场)H.Second Large Rectangle
    最大全1子矩阵的两种解法(例题:City Game HDU
    POJ
    Codeforces Round #588 (Div. 2) C
    1216E
    1221D
    BUY LOW, BUY LOWER, POJ
    Priest John's Busiest Day (2-sat)
    poj1080
  • 原文地址:https://www.cnblogs.com/polax/p/14418598.html
Copyright © 2011-2022 走看看