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

Implementing Internal Container Calls in Rancher Using http://service-name.namespace:port

New plan. Calling the addresses of the 3 applications from within other containers succeeds.

1. New deployment plan: we expect mutual calls between server-side containers to be based on service names rather than domain names. See Figure 1.

New deployment plan: we expect mutual calls between server-side containers to be based on service names rather than domain names.
Figure 1

2. Current plan. A single service’s container includes 3 applications, all configured to use port 80 and differentiated by domain name. Call URL: https://ccpapi.dev.chinamcloud.cn. See Figure 2.

Current plan. A single service's container includes 3 applications, all configured to use port 80 and differentiated by domain name. Call URL: https://ccpapi.dev.chinamcloud.cn.
Figure 2
Plaintext

https://ccpauth.dev.chinamcloud.cn
https://ccpapi.dev.chinamcloud.cn
https://ccprpc.dev.chinamcloud.cn

3. Current plan. A single service’s container includes 3 applications, all configured to use port 80 and differentiated by domain name. Call URL: https://ccpauth.dev.chinamcloud.cn. See Figure 3.

Current plan. A single service's container includes 3 applications, all configured to use port 80 and differentiated by domain name. Call URL: https://ccpauth.dev.chinamcloud.cn.
Figure 3

4. Current plan. The Nginx configuration file in the container contains the following:

Nginx
 
server {
    listen 80; ## listen for ipv4
    server_name ccpauth.dev.chinamcloud.cn;
    charset utf-8;

    root /mcloud/www/channel-pub-api/frontend/web;
    index index.php;

    location / {
        # 如果找不到真实存在的文件,把请求分发至 index.php
        try_files $uri $uri/ /index.php$is_args$args;
    }

    # uncomment to avoid processing of calls to non-existing static files by Yii
    #location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
    #    try_files $uri =404;
    #}
    #error_page 404 /404.html;

    # deny accessing php files for the /assets directory
    location ~ ^/assets/.*\.php$ {
        deny all;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~* /\. {
        deny all;
    }
}

server {
    listen 80; ## listen for ipv4
    server_name ccprpc.dev.chinamcloud.cn;
    charset utf-8;

    root /mcloud/www/channel-pub-api/rpc/web;
    index index.php;

    location / {
        # 如果找不到真实存在的文件,把请求分发至 index.php
        try_files $uri $uri/ /index.php$is_args$args;
    }

    # uncomment to avoid processing of calls to non-existing static files by Yii
    #location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
    #    try_files $uri =404;
    #}
    #error_page 404 /404.html;

    # deny accessing php files for the /assets directory
    location ~ ^/assets/.*\.php$ {
        deny all;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~* /\. {
        deny all;
    }
}

server {
    listen 80; ## listen for ipv4
    server_name ccpapi.dev.chinamcloud.cn localhost;
    charset utf-8;

    root /mcloud/www/channel-pub-api;
    index index.php;

    location / {
        root /mcloud/www/channel-pub-api/api/web;
        try_files $uri $uri/ /api/web/index.php$is_args$args;

        # omit static files logging, and if they don't exist, avoid processing by Yii (uncomment if necessary)
        #location ~ ^/.+\.(css|js|ico|png|jpe?g|gif|svg|ttf|mp4|mov|swf|pdf|zip|rar)$ {
        #    log_not_found off;
        #    access_log off;
        #    try_files $uri =404;
        #}

        location ~ ^/assets/.+\.php(/|$) {
            deny all;
        }
    }

    location /customize {
        alias /mcloud/www/channel-pub-api/customize/web/;
        location = /customize {
            try_files $uri /customize/customize/web/index.php$is_args$args;
        }
        try_files $uri $uri/ /customize/customize/web/index.php$is_args$args;
        location ~ ^/customize/assets/.+\.php(/|$) {
            deny all;
        }
    }

    location /baijia {
        alias /mcloud/www/channel-pub-api/baijia/web/;

        # redirect to the URL without a trailing slash (uncomment if necessary)
        #location = /baijia/ {
        #    return 301 /baijia;
        #}

        # prevent the directory redirect to the URL with a trailing slash
        location = /baijia {
            # if your location is "/baijia", try use "/baijia/baijia/web/index.php$is_args$args"
            # bug ticket: https://trac.nginx.org/nginx/ticket/97
            try_files $uri /baijia/baijia/web/index.php$is_args$args;
        }

        # if your location is "/baijia", try use "/baijia/baijia/web/index.php$is_args$args"
        # bug ticket: https://trac.nginx.org/nginx/ticket/97
        try_files $uri $uri/ /baijia/baijia/web/index.php$is_args$args;

        # omit static files logging, and if they don't exist, avoid processing by Yii (uncomment if necessary)
        #location ~ ^/baijia/.+\.(css|js|ico|png|jpe?g|gif|svg|ttf|mp4|mov|swf|pdf|zip|rar)$ {
        #    log_not_found off;
        #    access_log off;
        #    try_files $uri =404;
        #}

        location ~ ^/baijia/assets/.+\.php(/|$) {
            deny all;
        }
    }

    location /douyin {
            alias /mcloud/www/channel-pub-api/douyin/web/;

            # redirect to the URL without a trailing slash (uncomment if necessary)
            #location = /douyin/ {
            #    return 301 /douyin;
            #}

            # prevent the directory redirect to the URL with a trailing slash
            location = /douyin {
                # if your location is "/douyin", try use "/douyin/douyin/web/index.php$is_args$args"
                # bug ticket: https://trac.nginx.org/nginx/ticket/97
                try_files $uri /douyin/douyin/web/index.php$is_args$args;
            }

            # if your location is "/douyin", try use "/douyin/douyin/web/index.php$is_args$args"
            # bug ticket: https://trac.nginx.org/nginx/ticket/97
            try_files $uri $uri/ /douyin/douyin/web/index.php$is_args$args;

            # omit static files logging, and if they don't exist, avoid processing by Yii (uncomment if necessary)
            #location ~ ^/douyin/.+\.(css|js|ico|png|jpe?g|gif|svg|ttf|mp4|mov|swf|pdf|zip|rar)$ {
            #    log_not_found off;
            #    access_log off;
            #    try_files $uri =404;
            #}

            location ~ ^/douyin/assets/.+\.php(/|$) {
                deny all;
            }
        }

    location /netease {
        alias /mcloud/www/channel-pub-api/netease/web/;

        # redirect to the URL without a trailing slash (uncomment if necessary)
        #location = /netease/ {
        #    return 301 /netease;
        #}

        # prevent the directory redirect to the URL with a trailing slash
        location = /netease {
            # if your location is "/netease", try use "/netease/netease/web/index.php$is_args$args"
            # bug ticket: https://trac.nginx.org/nginx/ticket/97
            try_files $uri /netease/netease/web/index.php$is_args$args;
        }

        # if your location is "/netease", try use "/netease/netease/web/index.php$is_args$args"
        # bug ticket: https://trac.nginx.org/nginx/ticket/97
        try_files $uri $uri/ /netease/netease/web/index.php$is_args$args;

        # omit static files logging, and if they don't exist, avoid processing by Yii (uncomment if necessary)
        #location ~ ^/netease/.+\.(css|js|ico|png|jpe?g|gif|svg|ttf|mp4|mov|swf|pdf|zip|rar)$ {
        #    log_not_found off;
        #    access_log off;
        #    try_files $uri =404;
        #}

        location ~ ^/netease/assets/.+\.php(/|$) {
            deny all;
        }
    }

    location /qq {
        alias /mcloud/www/channel-pub-api/qq/web/;

        # redirect to the URL without a trailing slash (uncomment if necessary)
        #location = /qq/ {
        #    return 301 /qq;
        #}

        # prevent the directory redirect to the URL with a trailing slash
        location = /qq {
            # if your location is "/qq", try use "/qq/qq/web/index.php$is_args$args"
            # bug ticket: https://trac.nginx.org/nginx/ticket/97
            try_files $uri /qq/qq/web/index.php$is_args$args;
        }

        # if your location is "/qq", try use "/qq/qq/web/index.php$is_args$args"
        # bug ticket: https://trac.nginx.org/nginx/ticket/97
        try_files $uri $uri/ /qq/qq/web/index.php$is_args$args;

        # omit static files logging, and if they don't exist, avoid processing by Yii (uncomment if necessary)
        #location ~ ^/qq/.+\.(css|js|ico|png|jpe?g|gif|svg|ttf|mp4|mov|swf|pdf|zip|rar)$ {
        #    log_not_found off;
        #    access_log off;
        #    try_files $uri =404;
        #}

        location ~ ^/qq/assets/.+\.php(/|$) {
            deny all;
        }
    }

    location /vtt {
        alias /mcloud/www/channel-pub-api/vtt/web/;

        # redirect to the URL without a trailing slash (uncomment if necessary)
        #location = /vtt/ {
        #    return 301 /vtt;
        #}

        # prevent the directory redirect to the URL with a trailing slash
        location = /vtt {
            # if your location is "/vtt", try use "/vtt/vtt/web/index.php$is_args$args"
            # bug ticket: https://trac.nginx.org/nginx/ticket/97
            try_files $uri /vtt/vtt/web/index.php$is_args$args;
        }

        # if your location is "/vtt", try use "/vtt/vtt/web/index.php$is_args$args"
        # bug ticket: https://trac.nginx.org/nginx/ticket/97
        try_files $uri $uri/ /vtt/vtt/web/index.php$is_args$args;

        # omit static files logging, and if they don't exist, avoid processing by Yii (uncomment if necessary)
        #location ~ ^/vtt/.+\.(css|js|ico|png|jpe?g|gif|svg|ttf|mp4|mov|swf|pdf|zip|rar)$ {
        #    log_not_found off;
        #    access_log off;
        #    try_files $uri =404;
        #}

        location ~ ^/vtt/assets/.+\.php(/|$) {
            deny all;
        }
    }

    location /weibo {
        alias /mcloud/www/channel-pub-api/weibo/web/;

        # redirect to the URL without a trailing slash (uncomment if necessary)
        #location = /weibo/ {
        #    return 301 /weibo;
        #}

        # prevent the directory redirect to the URL with a trailing slash
        location = /weibo {
            # if your location is "/weibo", try use "/weibo/weibo/web/index.php$is_args$args"
            # bug ticket: https://trac.nginx.org/nginx/ticket/97
            try_files $uri /weibo/weibo/web/index.php$is_args$args;
        }

        # if your location is "/weibo", try use "/weibo/weibo/web/index.php$is_args$args"
        # bug ticket: https://trac.nginx.org/nginx/ticket/97
        try_files $uri $uri/ /weibo/weibo/web/index.php$is_args$args;

        # omit static files logging, and if they don't exist, avoid processing by Yii (uncomment if necessary)
        #location ~ ^/weibo/.+\.(css|js|ico|png|jpe?g|gif|svg|ttf|mp4|mov|swf|pdf|zip|rar)$ {
        #    log_not_found off;
        #    access_log off;
        #    try_files $uri =404;
        #}

        location ~ ^/weibo/assets/.+\.php(/|$) {
            deny all;
        }
    }

    location /wx {
        alias /mcloud/www/channel-pub-api/wx/web/;

        # redirect to the URL without a trailing slash (uncomment if necessary)
        #location = /wx/ {
        #    return 301 /wx;
        #}

        # prevent the directory redirect to the URL with a trailing slash
        location = /wx {
            # if your location is "/wx", try use "/wx/wx/web/index.php$is_args$args"
            # bug ticket: https://trac.nginx.org/nginx/ticket/97
            try_files $uri /wx/wx/web/index.php$is_args$args;
        }

        # if your location is "/wx", try use "/wx/wx/web/index.php$is_args$args"
        # bug ticket: https://trac.nginx.org/nginx/ticket/97
        try_files $uri $uri/ /wx/wx/web/index.php$is_args$args;

        # omit static files logging, and if they don't exist, avoid processing by Yii (uncomment if necessary)
        #location ~ ^/wx/.+\.(css|js|ico|png|jpe?g|gif|svg|ttf|mp4|mov|swf|pdf|zip|rar)$ {
        #    log_not_found off;
        #    access_log off;
        #    try_files $uri =404;
        #}

        location ~ ^/wx/assets/.+\.php(/|$) {
            deny all;
        }
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
        location ~ ^/.+\.php(/|$) {
                rewrite (?!^/((api|customize|baijia|customize|douyin|netease|qq|vtt|weibo|wx)/web|baijia|customize|douyin|netease|qq|vtt|weibo|wx))^ /api/web$uri break;
                rewrite (?!^/baijia/web)^/baijia(/.+)$ /baijia/web$1 break;
                rewrite (?!^/customize/web)^/customize(/.+)$ /customize/web$1 break;
                rewrite (?!^/douyin/web)^/douyin(/.+)$ /douyin/web$1 break;
                rewrite (?!^/netease/web)^/netease(/.+)$ /netease/web$1 break;
                rewrite (?!^/qq/web)^/qq(/.+)$ /qq/web$1 break;
                rewrite (?!^/vtt/web)^/vtt(/.+)$ /vtt/web$1 break;
                rewrite (?!^/weibo/web)^/weibo(/.+)$ /weibo/web$1 break;
                rewrite (?!^/wx/web)^/wx(/.+)$ /wx/web$1 break;

                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_pass 127.0.0.1:9000;
                #fastcgi_pass unix:/var/run/php5-fpm.sock;
                try_files $fastcgi_script_name =404;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\. {
        deny all;
    }
}

5. Current plan. Reviewing the load balancing rules, they are all custom domains. See Figure 4.

Current plan. Reviewing the load balancing rules, they are all custom domains.
Figure 4

6. New plan. A single service’s container includes 3 applications. ccpauth needs to support an external domain name and does not need to support internal calls. ccpapi and ccprpc need to support internal service name calls and do not need to support external calls. Their ports are configured as 80, 82, and 83 respectively, differentiated by port.

Plaintext

https://ccpauth.dev.chinamcloud.cn
http://ccpapi.ccp:82
http://ccpapi.ccp:83

7. New plan. The Nginx configuration file in the container contains the following:

Nginx

server {
    listen 80; ## listen for ipv4
    server_name ccpauth.dev.chinamcloud.cn;
    charset utf-8;

    root /mcloud/www/channel-pub-api/frontend/web;
    index index.php;

    location / {
        # 如果找不到真实存在的文件,把请求分发至 index.php
        try_files $uri $uri/ /index.php$is_args$args;
    }

    # uncomment to avoid processing of calls to non-existing static files by Yii
    #location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
    #    try_files $uri =404;
    #}
    #error_page 404 /404.html;

    # deny accessing php files for the /assets directory
    location ~ ^/assets/.*\.php$ {
        deny all;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~* /\. {
        deny all;
    }
}

server {
    listen 83; ## listen for ipv4
    server_name ccpapi.ccp;
    charset utf-8;

    root /mcloud/www/channel-pub-api/rpc/web;
    index index.php;

    location / {
        # 如果找不到真实存在的文件,把请求分发至 index.php
        try_files $uri $uri/ /index.php$is_args$args;
    }

    # uncomment to avoid processing of calls to non-existing static files by Yii
    #location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
    #    try_files $uri =404;
    #}
    #error_page 404 /404.html;

    # deny accessing php files for the /assets directory
    location ~ ^/assets/.*\.php$ {
        deny all;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~* /\. {
        deny all;
    }
}

server {
    listen 82; ## listen for ipv4
    server_name ccpapi.ccp localhost;
    charset utf-8;

    root /mcloud/www/channel-pub-api;
    index index.php;

    location / {
        root /mcloud/www/channel-pub-api/api/web;
        try_files $uri $uri/ /api/web/index.php$is_args$args;

        # omit static files logging, and if they don't exist, avoid processing by Yii (uncomment if necessary)
        #location ~ ^/.+\.(css|js|ico|png|jpe?g|gif|svg|ttf|mp4|mov|swf|pdf|zip|rar)$ {
        #    log_not_found off;
        #    access_log off;
        #    try_files $uri =404;
        #}

        location ~ ^/assets/.+\.php(/|$) {
            deny all;
        }
    }

    location /customize {
        alias /mcloud/www/channel-pub-api/customize/web/;
        location = /customize {
            try_files $uri /customize/customize/web/index.php$is_args$args;
        }
        try_files $uri $uri/ /customize/customize/web/index.php$is_args$args;
        location ~ ^/customize/assets/.+\.php(/|$) {
            deny all;
        }
    }

    location /baijia {
        alias /mcloud/www/channel-pub-api/baijia/web/;

        # redirect to the URL without a trailing slash (uncomment if necessary)
        #location = /baijia/ {
        #    return 301 /baijia;
        #}

        # prevent the directory redirect to the URL with a trailing slash
        location = /baijia {
            # if your location is "/baijia", try use "/baijia/baijia/web/index.php$is_args$args"
            # bug ticket: https://trac.nginx.org/nginx/ticket/97
            try_files $uri /baijia/baijia/web/index.php$is_args$args;
        }

        # if your location is "/baijia", try use "/baijia/baijia/web/index.php$is_args$args"
        # bug ticket: https://trac.nginx.org/nginx/ticket/97
        try_files $uri $uri/ /baijia/baijia/web/index.php$is_args$args;

        # omit static files logging, and if they don't exist, avoid processing by Yii (uncomment if necessary)
        #location ~ ^/baijia/.+\.(css|js|ico|png|jpe?g|gif|svg|ttf|mp4|mov|swf|pdf|zip|rar)$ {
        #    log_not_found off;
        #    access_log off;
        #    try_files $uri =404;
        #}

        location ~ ^/baijia/assets/.+\.php(/|$) {
            deny all;
        }
    }

    location /douyin {
            alias /mcloud/www/channel-pub-api/douyin/web/;

            # redirect to the URL without a trailing slash (uncomment if necessary)
            #location = /douyin/ {
            #    return 301 /douyin;
            #}

            # prevent the directory redirect to the URL with a trailing slash
            location = /douyin {
                # if your location is "/douyin", try use "/douyin/douyin/web/index.php$is_args$args"
                # bug ticket: https://trac.nginx.org/nginx/ticket/97
                try_files $uri /douyin/douyin/web/index.php$is_args$args;
            }

            # if your location is "/douyin", try use "/douyin/douyin/web/index.php$is_args$args"
            # bug ticket: https://trac.nginx.org/nginx/ticket/97
            try_files $uri $uri/ /douyin/douyin/web/index.php$is_args$args;

            # omit static files logging, and if they don't exist, avoid processing by Yii (uncomment if necessary)
            #location ~ ^/douyin/.+\.(css|js|ico|png|jpe?g|gif|svg|ttf|mp4|mov|swf|pdf|zip|rar)$ {
            #    log_not_found off;
            #    access_log off;
            #    try_files $uri =404;
            #}

            location ~ ^/douyin/assets/.+\.php(/|$) {
                deny all;
            }
        }

    location /netease {
        alias /mcloud/www/channel-pub-api/netease/web/;

        # redirect to the URL without a trailing slash (uncomment if necessary)
        #location = /netease/ {
        #    return 301 /netease;
        #}

        # prevent the directory redirect to the URL with a trailing slash
        location = /netease {
            # if your location is "/netease", try use "/netease/netease/web/index.php$is_args$args"
            # bug ticket: https://trac.nginx.org/nginx/ticket/97
            try_files $uri /netease/netease/web/index.php$is_args$args;
        }

        # if your location is "/netease", try use "/netease/netease/web/index.php$is_args$args"
        # bug ticket: https://trac.nginx.org/nginx/ticket/97
        try_files $uri $uri/ /netease/netease/web/index.php$is_args$args;

        # omit static files logging, and if they don't exist, avoid processing by Yii (uncomment if necessary)
        #location ~ ^/netease/.+\.(css|js|ico|png|jpe?g|gif|svg|ttf|mp4|mov|swf|pdf|zip|rar)$ {
        #    log_not_found off;
        #    access_log off;
        #    try_files $uri =404;
        #}

        location ~ ^/netease/assets/.+\.php(/|$) {
            deny all;
        }
    }

    location /qq {
        alias /mcloud/www/channel-pub-api/qq/web/;

        # redirect to the URL without a trailing slash (uncomment if necessary)
        #location = /qq/ {
        #    return 301 /qq;
        #}

        # prevent the directory redirect to the URL with a trailing slash
        location = /qq {
            # if your location is "/qq", try use "/qq/qq/web/index.php$is_args$args"
            # bug ticket: https://trac.nginx.org/nginx/ticket/97
            try_files $uri /qq/qq/web/index.php$is_args$args;
        }

        # if your location is "/qq", try use "/qq/qq/web/index.php$is_args$args"
        # bug ticket: https://trac.nginx.org/nginx/ticket/97
        try_files $uri $uri/ /qq/qq/web/index.php$is_args$args;

        # omit static files logging, and if they don't exist, avoid processing by Yii (uncomment if necessary)
        #location ~ ^/qq/.+\.(css|js|ico|png|jpe?g|gif|svg|ttf|mp4|mov|swf|pdf|zip|rar)$ {
        #    log_not_found off;
        #    access_log off;
        #    try_files $uri =404;
        #}

        location ~ ^/qq/assets/.+\.php(/|$) {
            deny all;
        }
    }

    location /vtt {
        alias /mcloud/www/channel-pub-api/vtt/web/;

        # redirect to the URL without a trailing slash (uncomment if necessary)
        #location = /vtt/ {
        #    return 301 /vtt;
        #}

        # prevent the directory redirect to the URL with a trailing slash
        location = /vtt {
            # if your location is "/vtt", try use "/vtt/vtt/web/index.php$is_args$args"
            # bug ticket: https://trac.nginx.org/nginx/ticket/97
            try_files $uri /vtt/vtt/web/index.php$is_args$args;
        }

        # if your location is "/vtt", try use "/vtt/vtt/web/index.php$is_args$args"
        # bug ticket: https://trac.nginx.org/nginx/ticket/97
        try_files $uri $uri/ /vtt/vtt/web/index.php$is_args$args;

        # omit static files logging, and if they don't exist, avoid processing by Yii (uncomment if necessary)
        #location ~ ^/vtt/.+\.(css|js|ico|png|jpe?g|gif|svg|ttf|mp4|mov|swf|pdf|zip|rar)$ {
        #    log_not_found off;
        #    access_log off;
        #    try_files $uri =404;
        #}

        location ~ ^/vtt/assets/.+\.php(/|$) {
            deny all;
        }
    }

    location /weibo {
        alias /mcloud/www/channel-pub-api/weibo/web/;

        # redirect to the URL without a trailing slash (uncomment if necessary)
        #location = /weibo/ {
        #    return 301 /weibo;
        #}

        # prevent the directory redirect to the URL with a trailing slash
        location = /weibo {
            # if your location is "/weibo", try use "/weibo/weibo/web/index.php$is_args$args"
            # bug ticket: https://trac.nginx.org/nginx/ticket/97
            try_files $uri /weibo/weibo/web/index.php$is_args$args;
        }

        # if your location is "/weibo", try use "/weibo/weibo/web/index.php$is_args$args"
        # bug ticket: https://trac.nginx.org/nginx/ticket/97
        try_files $uri $uri/ /weibo/weibo/web/index.php$is_args$args;

        # omit static files logging, and if they don't exist, avoid processing by Yii (uncomment if necessary)
        #location ~ ^/weibo/.+\.(css|js|ico|png|jpe?g|gif|svg|ttf|mp4|mov|swf|pdf|zip|rar)$ {
        #    log_not_found off;
        #    access_log off;
        #    try_files $uri =404;
        #}

        location ~ ^/weibo/assets/.+\.php(/|$) {
            deny all;
        }
    }

    location /wx {
        alias /mcloud/www/channel-pub-api/wx/web/;

        # redirect to the URL without a trailing slash (uncomment if necessary)
        #location = /wx/ {
        #    return 301 /wx;
        #}

        # prevent the directory redirect to the URL with a trailing slash
        location = /wx {
            # if your location is "/wx", try use "/wx/wx/web/index.php$is_args$args"
            # bug ticket: https://trac.nginx.org/nginx/ticket/97
            try_files $uri /wx/wx/web/index.php$is_args$args;
        }

        # if your location is "/wx", try use "/wx/wx/web/index.php$is_args$args"
        # bug ticket: https://trac.nginx.org/nginx/ticket/97
        try_files $uri $uri/ /wx/wx/web/index.php$is_args$args;

        # omit static files logging, and if they don't exist, avoid processing by Yii (uncomment if necessary)
        #location ~ ^/wx/.+\.(css|js|ico|png|jpe?g|gif|svg|ttf|mp4|mov|swf|pdf|zip|rar)$ {
        #    log_not_found off;
        #    access_log off;
        #    try_files $uri =404;
        #}

        location ~ ^/wx/assets/.+\.php(/|$) {
            deny all;
        }
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
        location ~ ^/.+\.php(/|$) {
                rewrite (?!^/((api|customize|baijia|customize|douyin|netease|qq|vtt|weibo|wx)/web|baijia|customize|douyin|netease|qq|vtt|weibo|wx))^ /api/web$uri break;
                rewrite (?!^/baijia/web)^/baijia(/.+)$ /baijia/web$1 break;
                rewrite (?!^/customize/web)^/customize(/.+)$ /customize/web$1 break;
                rewrite (?!^/douyin/web)^/douyin(/.+)$ /douyin/web$1 break;
                rewrite (?!^/netease/web)^/netease(/.+)$ /netease/web$1 break;
                rewrite (?!^/qq/web)^/qq(/.+)$ /qq/web$1 break;
                rewrite (?!^/vtt/web)^/vtt(/.+)$ /vtt/web$1 break;
                rewrite (?!^/weibo/web)^/weibo(/.+)$ /weibo/web$1 break;
                rewrite (?!^/wx/web)^/wx(/.+)$ /wx/web$1 break;

                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_pass 127.0.0.1:9000;
                #fastcgi_pass unix:/var/run/php5-fpm.sock;
                try_files $fastcgi_script_name =404;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\. {
        deny all;
    }
}

8. New plan. Reviewing the load balancing rules, only ccpauth.dev.chinamcloud.cn is retained. See Figure 5.

New plan. Reviewing the load balancing rules, only ccpauth.dev.chinamcloud.cn is retained.
Figure 5

9. New plan. Calling the addresses of the 3 applications from within the container itself succeeds.

Plaintext

[root@ccpapi-78d6f74688-rfjhf /]# cd /mcloud/www/channel-pub-api/
[root@ccpapi-78d6f74688-rfjhf channel-pub-api]# cd api/web/
[root@ccpapi-78d6f74688-rfjhf web]# vi api.txt
[root@ccpapi-78d6f74688-rfjhf web]# cd ..
[root@ccpapi-78d6f74688-rfjhf api]# cd ..
[root@ccpapi-78d6f74688-rfjhf channel-pub-api]# cd qq/web/
[root@ccpapi-78d6f74688-rfjhf web]# vi qq.txt
[root@ccpapi-78d6f74688-rfjhf web]# cd rpc/web
bash: cd: rpc/web: No such file or directory
[root@ccpapi-78d6f74688-rfjhf web]# cd ..
[root@ccpapi-78d6f74688-rfjhf qq]# cd ..
[root@ccpapi-78d6f74688-rfjhf channel-pub-api]# cd rpc/web/
[root@ccpapi-78d6f74688-rfjhf web]# vi rpc.txt
[root@ccpapi-78d6f74688-rfjhf web]# cd ..
[root@ccpapi-78d6f74688-rfjhf rpc]# cd ..
[root@ccpapi-78d6f74688-rfjhf channel-pub-api]# cd frontend/web/
[root@ccpapi-78d6f74688-rfjhf web]# vi auth.txt
[root@ccpapi-78d6f74688-rfjhf web]# curl http://ccpapi.ccp:82/api.txt
api
[root@ccpapi-78d6f74688-rfjhf web]# curl http://ccpapi.ccp:82/qq/qq.txt
qq
[root@ccpapi-78d6f74688-rfjhf web]# curl http://ccpapi.ccp:83/rpc.txt
rpc
[root@ccpapi-78d6f74688-rfjhf web]# curl https://ccpauth.dev.chinamcloud.cn/auth.txt
auth
[root@ccpapi-78d6f74688-rfjhf web]# 

10. New plan. Calling the addresses of the 3 applications from within other containers succeeds. See Figure 6.

New plan. Calling the addresses of the 3 applications from within other containers succeeds.
Figure 6
Plaintext

[root@ccpvtt-54dc6fb788-t9ldd /]# curl http://ccpapi.ccp:82/api.txt
api
[root@ccpvtt-54dc6fb788-t9ldd /]# curl http://ccpapi.ccp:82/qq/qq.txt
qq
[root@ccpvtt-54dc6fb788-t9ldd /]# curl http://ccpapi.ccp:83/rpc.txt
rpc
[root@ccpvtt-54dc6fb788-t9ldd /]# curl https://ccpauth.dev.chinamcloud.cn/auth.txt
auth
[root@ccpvtt-54dc6fb788-t9ldd /]# 

11. New plan. Calling the URLs sequentially from the external network. Checking the results. They meet expectations.

Plaintext
https://ccpauth.dev.chinamcloud.cn/auth.txt responds successfully, auth
https://ccpapi.dev.chinamcloud.cn/api.txt responds 404, 404 Not Found
https://ccprpc.dev.chinamcloud.cn/rpc.txt responds 404, 404 Not Found
http://ccpapi.ccp:82/api.txt no response, Failed to load response data
http://ccpapi.ccp:83/rpc.txt no response, Failed to load response data

12. Because in the development environment, the local environments of other services might need to call ccpapi and ccprpc, ccpapi and ccprpc must support external calls. Edit the load balancing rules for ccpapi.dev.chinamcloud.cn:82 and ccprpc.dev.chinamcloud.cn:83. See Figure 7.

Because in the development environment, the local environments of other services might need to call ccpapi and ccprpc, ccpapi and ccprpc must support external calls. Edit the load balancing rules for ccpapi.dev.chinamcloud.cn:82 and ccprpc.dev.chinamcloud.cn:83.
Figure 7

13. New plan. Calling the URLs sequentially from the external network. Checking the results. They meet expectations.

Plaintext
https://ccpauth.dev.chinamcloud.cn/auth.txt responds successfully, auth
https://ccpapi.dev.chinamcloud.cn/api.txt responds successfully, api
https://ccprpc.dev.chinamcloud.cn/rpc.txt responds successfully, rpc
http://ccpapi.ccp:82/api.txt no response, Failed to load response data
http://ccpapi.ccp:83/rpc.txt no response, Failed to load response data

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

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

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

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

关于我  ·  GitHub  ·  邮件联系