We use a small VM on GCE to redirect certain HTTP requests to canonical destinations (e.g. *.bazel.io -> *.bazel.build).
yum upgradeyum install nginxcat > /etc/nginx/nginx.conf <<'EOF'
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Redirect variations of the main website URL to the canonical one.
server {
listen 80;
server_name bazel.build www.bazel.build bazel.io www.bazel.io;
return 301 https://bazel.build$request_uri;
}
# Redirect http:// to https:// and *.bazel.io to *.bazel.build.
server {
listen 80;
server_name ~^(?<subdomain>.+)\.bazel\.(?<tld>.+)$;
return 301 https://$subdomain.bazel.build$request_uri;
}
# Catch-all default server that just returns an error.
server {
listen 80 default_server;
server_name _;
add_header Content-Type text/plain;
return 200 "Bazel Redirection Service";
}
}
EOF
systemctl enable nginxsystemctl start nginx