没有不值得去解决的问题,也没有不值得去学习的技术!

Implementing Docker Deployment for Yii 2.0 With Single and Multi-Domain Support

Changed from multiple-domain mode to single-domain mode, modified the file: frontend/config/main.php.

1. To change from multiple-domain mode to single-domain mode, I modified the file: frontend/config/main.php. See Figure 1.

Changed from multiple-domain mode to single-domain mode, modified the file: frontend/config/main.php.
Figure 1

2. To change from multiple-domain mode to single-domain mode, I modified the file: etc/nginx/conf.d/ccp_api.conf. See Figure 2.

Changed from multiple-domain mode to single-domain mode, modified the file: etc/nginx/conf.d/ccp_api.conf.
Figure 2

3. I now plan to allow switching the domain mode during container upgrades based on the environment variable: CHANNEL_PUB_API_CFG_FRONTEND_DOMAIN_MODE=single|multiple. Default: single.

4. I decided to prepare two sets of files for the multiple-domain mode and use a shell script to check the environment variable CHANNEL_PUB_API_CFG_DOMAIN_NAME_MODE=multiple and execute the file copy accordingly.

5. I edited the shell script /config/init/config.sh, placing it before the other shell scripts. See Figure 3.

Edited the shell script /config/init/config.sh. Placed it before the other shell scripts.
Figure 3
ShellScript

#!/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 failed to start. The reason was that config0.sh executed before config.sh. I renamed config.sh to ccp_init.sh.

Plaintext

[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 started. See Figure 4.

Nginx has started.
Figure 4
Plaintext

[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 /]#

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系