PHP.and.MySQL.Create.Modify.Reuse
PHP&MySQL范例精解_創(chuàng)建握童、修改、重用-docker環(huán)境搭建-4.準(zhǔn)備apache
準(zhǔn)備apache
拉取apache鏡像
docker pull httpd:2.4.37-alpine
臨時(shí)容器
$ docker run -d --rm --name tmp-httpd httpd:2.4.37-alpine
進(jìn)入容器看下網(wǎng)站的根目錄在哪里
jjkkll$ bash -c "clear && docker exec -it tmp-httpd sh"
安裝mlocate
apk add mlocate
更新mlocate的數(shù)據(jù)庫(kù)
updatedb
查找配置文件
locate httpd.conf
可以找到相關(guān)的2個(gè)目錄:
/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/
可以看到已經(jīng)被復(fù)制到容器外
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
若要測(cè)試httpd運(yùn)行網(wǎng)站
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
測(cè)試httpd運(yùn)行網(wǎng)站成功溪掀。
修改配置
/Users/jjkkll/Documents/2020-book-read/7302195625/docker/httpd-2.4.37-conf/conf/httpd.conf
找到這四個(gè)配置揪胃,把前面的#
號(hào)去掉
# 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默認(rèn)的DocumentRoot,以及相關(guān)設(shè)置喊递。
httpd-vhosts.conf 添加如下配置
/Users/jjkkll/Documents/2020-book-read/7302195625/docker/httpd-2.4.37-conf/conf/extra/httpd-vhosts.conf
# 添加如下配置
<VirtualHost *:80>
DocumentRoot "/usr/local/apache2/htdocs"
<Directory "/usr/local/apache2/htdocs">
Options None
Require all granted
</Directory>
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://virhuiai-php-fpm56:9000/var/www/html/$1
</VirtualHost>
ProxyRequests Off 就是啟用httpd的反向代理功能
virhuiai-php-fpm56是我們的php容器要使用的名字,都加入了同一個(gè)網(wǎng)絡(luò)virhuiai_nw,可以這樣用容器名相互訪問(wèn).