PHP&MySQL范例精解_创建、修改、重用-docker环境搭建-4.准备apache

PHP.and.MySQL.Create.Modify.Reuse
PHP&MySQL范例精解_创建、修改、重用-docker环境搭建-4.准备apache

准备apache

拉取apache镜像

docker pull httpd:2.4.37-alpine

临时容器

$ docker run -d --rm --name tmp-httpd httpd:2.4.37-alpine

进入容器看下网站的根目录在哪里

jjkkll$ bash -c "clear && docker exec -it tmp-httpd sh"

安装mlocate

apk add mlocate

更新mlocate的数据库

updatedb

查找配置文件

locate httpd.conf

可以找到相关的2个目录:

/usr/local/apache2/conf
/usr/local/apache2/htdocs

拷贝配置

$ docker cp tmp-httpd:/usr/local/apache2/conf /Users/jjkkll/Documents/2020-book-read/7302195625/docker/httpd-2.4.37-conf/

可以看到已经被复制到容器外

localhost:~ jjkkll$ tree -N /Users/jjkkll/Documents/2020-book-read/7302195625/docker/httpd-2.4.37-conf/
/Users/jjkkll/Documents/2020-book-read/7302195625/docker/httpd-2.4.37-conf/
└── conf
    ├── extra
    │   ├── httpd-autoindex.conf
    │   ├── httpd-dav.conf
    │   ├── httpd-default.conf
    │   ├── httpd-info.conf
    │   ├── httpd-languages.conf
    │   ├── httpd-manual.conf
    │   ├── httpd-mpm.conf
    │   ├── httpd-multilang-errordoc.conf
    │   ├── httpd-ssl.conf
    │   ├── httpd-userdir.conf
    │   ├── httpd-vhosts.conf
    │   └── proxy-html.conf
    ├── httpd.conf
    ├── magic
    ├── mime.types
    └── original
        ├── extra
        │   ├── httpd-autoindex.conf
        │   ├── httpd-dav.conf
        │   ├── httpd-default.conf
        │   ├── httpd-info.conf
        │   ├── httpd-languages.conf
        │   ├── httpd-manual.conf
        │   ├── httpd-mpm.conf
        │   ├── httpd-multilang-errordoc.conf
        │   ├── httpd-ssl.conf
        │   ├── httpd-userdir.conf
        │   ├── httpd-vhosts.conf
        │   └── proxy-html.conf
        └── httpd.conf

退出该容器

#Ctrl+D退出该容器
$ docker container stop tmp-httpd

若要测试httpd运行网站

docker run -d --rm -p 80:80 --name tmp-httpd httpd:2.4.37-alpine
bash -c "clear && docker exec -it tmp-httpd sh"
echo 'hello docker,hi csh!' > /usr/local/apache2/htdocs/index.html 

测试httpd运行网站成功。

image.png

修改配置

/Users/jjkkll/Documents/2020-book-read/7302195625/docker/httpd-2.4.37-conf/conf/httpd.conf

找到这四个配置,把前面的#号去掉

# 2018-11-27 17:14:31 去除注释
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
# 2020-04-06 15:51:11 去除注释
Include conf/extra/httpd-vhosts.conf

删除httpd.conf默认的DocumentRoot,以及相关设置。

httpd-vhosts.conf 添加如下配置

/Users/jjkkll/Documents/2020-book-read/7302195625/docker/httpd-2.4.37-conf/conf/extra/httpd-vhosts.conf
# 添加如下配置

    DocumentRoot "/usr/local/apache2/htdocs"
    
     Options None
     Require all granted
    
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://virhuiai-php-fpm56:9000/var/www/html/$1

ProxyRequests Off 就是启用httpd的反向代理功能

virhuiai-php-fpm56是我们的php容器要使用的名字,都加入了同一个网络virhuiai_nw,可以这样用容器名相互访问.

你可能感兴趣的:(PHP&MySQL范例精解_创建、修改、重用-docker环境搭建-4.准备apache)