I created 6 instances in Google Cloud Plateform
- 2 in asia
- 2 in us
- 2 in europe
I have 3 groups in each zone
When i try to go to my app, i'm randomly send to one zone, no matter if i'm in Europe or an other place.
For info, i followed this documentation https://cloud.google.com/compute/docs/load-balancing/http/cross-region-example
I just add one zone and remove http conf.
There is no traffic on the 6 instances, only me. All the 6 instances are available et health check are positif.
Here is my last result when i just refresh the page :
- Asia
- Europe
- US
- Europe
- Asia
- Asia
If you have any idea or if you need more details to help me, just ask, i will.
Update 1
In each instance i have one nginx with one default conf :
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name _;
ssl_certificate /etc/nginx/ssl/secure.crt;
ssl_certificate_key /etc/nginx/ssl/mysecure.key;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
}
Then i have my application conf :
server {
listen 443 ssl;
server_name myapp.example.com www.myapp.example.com;
ssl_certificate /etc/nginx/ssl/secure.crt;
ssl_certificate_key /etc/nginx/ssl/mysecure.key;
root /usr/share/nginx/html/app/web;
error_log /var/log/nginx/myapp.example.com_error.log;
access_log /var/log/nginx/myapp.example.com.log;
if ($http_x_forwarded_proto = "http") {
return 301 https://$host$request_uri;
}
location / {
# try to serve file directly, fallback to app.php
try_files $uri /app.php$is_args$args;
}
# PROD
location ~ ^/app\.php(/|$) {
fastcgi_pass php:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
internal;
}
}
When i go to https://ip-load-balancer, it's working perfectly, always get the closest instance.
But when i try https://myapp.example.com, it's goes wrong, i can see in the log that there is some redirect. Also when i check the log of the load balancer, he send the request to the good instance, but then i don't understand how to follow the request.
Thanks
It was a problem on the nginx. I have multi nginx stack, and for each request they received, they do a roundrobin to call the write php.
The PHP stack were on the 6 servers so it was random.
I change it to create 3 differents stack for each region.
PS: i am using docker with rancher.