Yii 2.0 Docker deployment, the implementation of single domain name and multi-domain name mode supported at the same time
1. Modify the multi-domain name mode to a single domain name mode, and modify the file: frontend/config/main.php. as shown in Figure 1
2. Modify the multi-domain name mode to single-domain name mode, and modify the file: etc/nginx/conf.d/ccp_api.conf. as shown in Figure 2
3. Now plan to upgrade the container based on the environment variable: channel_pub_api_cfg_frontend_domain_mode=single|multiple. Default: single. Switchable domain name mode.
4. Decide to prepare two documents under multiple domain names, and judge the environment variables based on the shell script: channel_pub_api_cfg_domain_name_mode=multiple, and execute the file copy.
5. Edit the shell script, /config/init/config.sh. before other shell scripts. as shown in Figure 3
#!/bin/bash
env | grep CHANNEL_PUB_API_CFG_FRONTEND_DOMAIN_MODE || export CHANNEL_PUB_API_CFG_FRONTEND_DOMAIN_MODE="single"
if [[ $CHANNEL_PUB_API_CFG_FRONTEND_DOMAIN_MODE == "multiple" ]]
then
\cp /mcloud/ccp_api.conf /etc/nginx/conf.d/
chmod +x /etc/nginx/conf.d/*
echo "前端的域名模式:多域名,复制 ccp_api.conf 至 /etc/nginx/conf.d/"
\cp /mcloud/frontend/config/main.php /mcloud/www/ccp_api/frontend/config/
echo "前端的域名模式:多域名,复制 main.php 至 /mcloud/www/ccp_api/frontend/config/"
elif [[ $CHANNEL_PUB_API_CFG_FRONTEND_DOMAIN_MODE == "single" ]]
then
echo "前端的域名模式:单域名"
else
echo "please set environment variable CHANNEL_PUB_API_CFG_FRONTEND_DOMAIN_MODE single or multiple"
fi
6. Nginx is not started. The reason is that config0.sh is executed before config.sh . Rename config.sh to CCP_init.sh.
[root@07ca67a1f3c1 conf.d]# nginx -t
nginx: [emerg] host not found in "CHANNEL_PUB_API_CFG_NGINX_AUTH_LISTEN" of the "listen" directive in /etc/nginx/conf.d/ccp_api.conf:2
nginx: configuration file /etc/nginx/nginx.conf test failed
[root@07ca67a1f3c1 conf.d]#
7. Nginx has been started. as shown in Figure 4
[root@b9b472c89102 /]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@b9b472c89102 /]#



