docker

2019-11-03  本文已影响0人  IT宝哥哥
  1. 创建容器
docker run --name mynginx -p 80:80 --network mybridge -v /etc/nginx/conf.d:/etc/nginc/conf.d:ro -v /var/www:/usr/share/nginx/html:ro -d nginx

--network 将该容器加入到指定的网络中,也可以后期指定:docker network connect mybridge mynginx
:ro readonly

docker run --name myphpfpm -p 9000:9000 --network mybridge -v /var/www:/var/www:ro -d php:7.3-fpm
docker run --name mydb -p 3306:3306 --network mybridge -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7

-e 指定环境变量

  1. 修改nginx配置
/default.conf
server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;
    root /usr/share/nginx/html;#这里是document_roo配置
    location / {
        #root   /usr/share/nginx/html;
        index  index.html index.htm;
        #proxy_pass http://127.0.0.1:8080;#反向代理设置
    }
    
    #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   php:9000;
   #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        #root          html;#默认设置路径
        fastcgi_pass   172.18.0.4:9000;#对应php-fpm的ip和端口
        fastcgi_index  index.php;
        #fastcgi_param  SCRIPT_FILENAME /scripts$fastcgi_script_name;#默认配置
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;#这里的document_root,就是location中root的设置
        include        fastcgi_params;
    }
    
    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}
上一篇 下一篇

猜你喜欢

热点阅读