在 Rancher 中通过 http://服务代号.命名空间:端口 内网调用各个容器的实现
1、新的部署规划,期望服务端的容器之间相互调用不再基于域名,而是基于服务名。如图1
2、现有的规划。一个服务的容器中包含 3 个应用,其端口皆配置为 80 ,基于域名区分。调用:https://ccpapi.dev.chinamcloud.cn 。如图2
3、现有的规划。一个服务的容器中包含 3 个应用,其端口皆配置为 80 ,基于域名区分。调用:https://ccpauth.dev.chinamcloud.cn 。如图3
4、现有的规划。容器中的 Nginx 配置文件内容如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 | 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、现有的规划。查看负载均衡的规则,皆是自定义域名。如图4
6、新的规划。一个服务的容器中包含 3 个应用,ccpauth 需要支持外网域名,无需要支持内网调用。ccpapi 与 ccprpc 需要支持内网服务名调用,无需要支持外网调用。其端口分别配置为 80、82、83 ,基于端口区分。
7、新的规划。容器中的 Nginx 配置文件内容如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 | 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、新的规划。查看负载均衡的规则,仅保留 ccpauth.dev.chinamcloud.cn。如图5
9、新的规划。在自身容器内部调用 3 个应用的地址,调用成功。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | [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、新的规划。在其他容器内部调用 3 个应用的地址,调用成功。如图6
1 2 3 4 5 6 7 8 9 | [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、新的规划。在外网中依次调用。查看结果。符合预期。
1 2 3 4 5 | https://ccpapi.dev.chinamcloud.cn/api.txt 响应 404,404 Not Found https://ccprpc.dev.chinamcloud.cn/rpc.txt 响应 404,404 Not Found http://ccpapi.ccp:82/api.txt 无响应,Failed to load response data http://ccpapi.ccp:83/rpc.txt 无响应,Failed to load response data |
12、由于在开发环境中,可能其他服务的本地环境需要调用 ccpapi 与 ccprpc。因此,需要 ccpapi 与 ccprpc 支持外网调用。编辑负载均衡的规则,ccpapi.dev.chinamcloud.cn:82、ccprpc.dev.chinamcloud.cn:83。如图7
13、新的规划。在外网中依次调用。查看结果。符合预期。
1 2 3 4 5 | http://ccpapi.ccp:82/api.txt 无响应,Failed to load response data http://ccpapi.ccp:83/rpc.txt 无响应,Failed to load response data |
近期评论