GCP Account with Pre-loaded Credits Setting Up Proxy Gateway on Google Cloud Compute Engine

GCP Account / 2026-05-16 19:52:05

Introduction to Proxy Gateways on Google Cloud

Setting up a proxy gateway on Google Cloud Compute Engine might sound like a complex task, but with the right guidance, it's surprisingly straightforward. A proxy gateway acts as an intermediary between your internal network and the internet, offering a controlled pathway for outbound or inbound traffic. This setup is invaluable for organizations needing to enforce security policies, cache frequently accessed content to save bandwidth, or bypass geo-restrictions for specific services. Whether you're a developer, IT administrator, or just someone looking for a secure and flexible networking solution, this guide will walk you through the process step by step. By the end, you'll have a fully functional proxy gateway on GCE, ready to handle your traffic needs with confidence. Let's dive in!

Why Use a Proxy Gateway on GCE?

A proxy gateway on Google Cloud Compute Engine serves multiple critical purposes. First, it enhances security by acting as a middleman that filters traffic. Instead of allowing direct access to internal resources from the internet, all requests pass through the proxy, which can block malicious payloads or unauthorized access attempts. Second, it enables content filtering—ideal for businesses needing to restrict access to certain websites or services. Third, caching content at the proxy level can significantly reduce bandwidth costs and improve load times for frequently accessed resources. For example, if multiple users in your organization access the same software updates, the proxy can serve cached versions instead of fetching them repeatedly from external servers.

Another key benefit is geo-restriction bypassing. If your organization needs to access region-locked services (like streaming platforms or localized APIs), routing traffic through a GCE instance in the desired region can make it appear as if the requests are coming from that location. Additionally, proxies provide anonymity by masking your original IP address, which is crucial for sensitive operations like web scraping or research.

From a cost perspective, Google Cloud's flexible pricing allows you to choose instance sizes that match your traffic needs, ensuring you don't overpay for unused resources. Plus, integrating with Google's global infrastructure ensures low latency and high availability. In short, a proxy gateway on GCE isn't just a technical tool—it's a strategic asset that balances security, efficiency, and scalability for modern workloads.

Prerequisites Before Starting

Before diving into the setup, ensure you have the following in place. First, a Google Cloud account with billing enabled. Without a functioning payment method, you won't be able to create Compute Engine instances. Next, you'll need a Google Cloud project. If you don't have one, create a new project via the Google Cloud Console. Make sure the Compute Engine API is enabled for your project—this is usually done automatically when you create an instance, but it's good to verify under "APIs & Services" in the console.

You should also have basic familiarity with the Linux command line, as most configuration will be done via SSH. If you're new to Linux, don't worry—this guide will walk you through every command. Additionally, you'll need a stable internet connection to manage your GCE instance and test the proxy. Lastly, plan your network topology: will you use a static external IP address for your proxy (recommended for consistency), and what firewall rules will be needed to allow traffic? Having these details ready will streamline the setup process and avoid common pitfalls.

Step 1: Creating Your Compute Engine Instance

The first step is creating a Compute Engine instance that will host your proxy gateway. Log in to your Google Cloud Console and navigate to "Compute Engine" > "VM instances". Click "Create Instance" to start the setup wizard.

For the instance name, choose something descriptive like "proxy-gateway" to easily identify it later. Select a region and zone based on your target audience or service requirements. For example, if your users are primarily in Europe, choose "europe-west1" and a specific zone within it. Choosing a zone close to your users minimizes latency.

Next, choose a machine type. For light traffic (fewer than 50 concurrent users), the e2-micro instance is sufficient and cost-effective. For heavier workloads, consider e2-medium or higher. Remember, the proxy's performance depends on CPU and network bandwidth—so scale accordingly.

For the boot disk, select Ubuntu 20.04 LTS (or another Linux distribution you're comfortable with). Allocate at least 10GB of storage—Squid's logs and cache can grow over time, so 10GB is a safe starting point. You can always resize later if needed.

Under "Networking", assign a static external IP address. This is crucial because if the IP changes, your clients will need reconfiguration. To do this, click "Configure" next to the external IP field, select "Static", and create a new static IP address. Name it something like "proxy-static-ip" for clarity.

In the "Firewall" section, check "Allow HTTP traffic" and "Allow HTTPS traffic" for now. We'll fine-tune these rules later in Step 3. Click "Create" to deploy the instance. Once it's ready (usually within 1-2 minutes), note the instance's external IP address—it'll be needed for later steps.

Choosing the Right Instance Type

Selecting the appropriate machine type is critical for balancing performance and cost. The e2-micro instance offers 1 vCPU and 1GB RAM, which is ideal for testing or very light use cases. However, if you plan to handle multiple concurrent connections or caching large files, consider upgrading to an e2-medium (2 vCPUs, 4GB RAM) or higher. Google Cloud's preemptible instances could be a cost-effective option for non-critical workloads, but they might get terminated unexpectedly—so avoid these for production proxies.

Also, consider the network egress costs. If your proxy will handle significant outbound traffic, a higher-tier instance with more bandwidth might save money in the long run by reducing additional egress fees. Always monitor usage after deployment and adjust the instance type if needed—Google Cloud makes it easy to resize instances with minimal downtime.

Setting Up Network Tags and Firewall Rules

Network tags help identify instances for firewall rules. When creating your instance, add a tag like 'proxy-server' to the 'Network tags' field. Later, you'll create a firewall rule that targets instances with this tag to allow specific ports. While the initial firewall settings during instance creation allow HTTP and HTTPS, we'll refine these to only permit traffic to your proxy port (e.g., 3128 for Squid). This minimizes attack surface by blocking unnecessary ports.

For now, don't worry too much about locking down the firewall—focus on deploying the instance first. We'll adjust firewall rules in detail in Step 3. Just ensure that SSH access (port 22) is enabled for administrative tasks.

Step 2: Installing and Configuring Squid Proxy

Once your instance is running, connect via SSH. In the Google Cloud Console, click the 'SSH' button next to your instance, or use a terminal with gcloud compute ssh [instance-name]. Now you're ready to install and configure Squid—a widely used open-source proxy server.

Begin by updating your system: sudo apt update && sudo apt upgrade -y. Then install Squid using sudo apt install squid -y. After installation, Squid runs by default on port 3128, but we need to configure it properly.

Installing Squid on Ubuntu/Debian

To install Squid, first update the package list with sudo apt update. Then install Squid with sudo apt install squid -y. This command fetches Squid from the official repositories and sets it up. Once installed, Squid starts automatically, but the default configuration is too permissive for production use—we'll fix that next.

Basic Configuration Settings

Open Squid's main configuration file with sudo nano /etc/squid/squid.conf. The default settings allow any IP to use the proxy, which is a security risk. Let's lock it down.

First, locate the 'acl' sections. Find the line that says '# http_access allow localnet' and replace it with specific rules. For example, add:

acl allowed_ips src 192.168.1.0/24 # Replace with your client IPs http_access allow allowed_ips http_access deny all

This ensures only specified IPs can use the proxy. Next, set the http_port to 3128 (or another port if needed):

http_port 3128

If you want to enable caching, uncomment or add:

cache_dir ufs /var/spool/squid 100 16 256

This creates a cache directory with 100MB size, 16 first-level directories, and 256 second-level directories. Adjust the size based on your storage capacity.

Save and exit the file, then restart Squid with sudo systemctl restart squid. Check status with sudo systemctl status squid to confirm it's running without errors.

Securing Your Proxy with Authentication

Open proxy servers are a big no-no—they can be exploited by attackers. To add authentication, install the apache2-utils package: sudo apt install apache2-utils -y. Then create a password file for Squid users:

sudo htpasswd -c /etc/squid/passwd username

Replace 'username' with your desired login. Enter a password when prompted. If adding more users, omit the -c flag:

sudo htpasswd /etc/squid/passwd anotheruser

Now, edit /etc/squid/squid.conf again. Add these lines before the http_access rules:

GCP Account with Pre-loaded Credits auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/passwd auth_param basic children 5 auth_param basic realm Squid Basic Authentication auth_param basic credentialsttl 2 hours acl authenticated_users proxy_auth REQUIRED http_access allow authenticated_users http_access deny all

This requires users to authenticate before accessing the proxy. Save and restart Squid. Test by trying to connect via a client—now it should prompt for a username and password.

Step 3: Configuring Google Cloud Firewall Rules

Now that Squid is configured, we need to adjust Google Cloud's firewall to allow proxy traffic while blocking unnecessary ports. Navigate to "VPC network" > "Firewall" in the console.

Allowing HTTP/HTTPS Traffic

Create a new firewall rule. Name it 'allow-proxy-traffic' and set the targets to 'Specified target tags'. In the 'Target tags' field, enter the tag you added earlier (e.g., 'proxy-server'). For sources, set to 'IP ranges' and enter the client IP ranges you want to allow (e.g., 'your-company-IP-range/24'). For protocols and ports, select 'tcp' and enter '3128' (or your Squid port). Save the rule.

Restricting Access by IP

For added security, restrict the firewall to only allow specific IPs. Instead of allowing '0.0.0.0/0', specify exact IP ranges for trusted clients. For example, if your office network is 192.168.1.0/24, enter that range. If you have remote workers, you can add their public IPs or use a VPN range. This ensures only authorized users can reach your proxy gateway.

Also, consider disabling SSH access from the internet. Change the existing SSH firewall rule to only allow your office IP or a bastion host. This reduces the risk of brute-force attacks on your VM.

Step 4: Testing Your Proxy Setup

Before declaring success, test your proxy thoroughly. On a client machine (outside your GCE network), configure your browser or system to use the proxy. Enter the GCE instance's static IP and port (3128). If you set up authentication, provide the credentials.

Use curl to test: curl -x http://[proxy-ip]:3128 http://example.com -U username:password. If successful, you'll see the HTML of example.com. Alternatively, visit a site like 'whatismyipaddress.com' through the proxy to verify your traffic is routed through the GCE instance's IP.

For Squid logs, check /var/log/squid/access.log. Each request will have timestamps, client IPs, and destination URLs. This helps confirm traffic is flowing correctly and spot any unauthorized attempts.

Advanced Configurations

GCP Account with Pre-loaded Credits Now that your proxy is running, explore advanced features to optimize performance and security.

SSL/TLS Termination

For HTTPS traffic, Squid can decrypt and re-encrypt connections (SSL bumping), but this requires careful setup. First, generate a CA certificate for signing SSL traffic. Use OpenSSL to create a CA:

openssl req -new -x509 -days 365 -nodes -out /etc/squid/ca.crt -keyout /etc/squid/ca.key

GCP Account with Pre-loaded Credits Then add these lines to squid.conf:

https_port 3129 cert=/etc/squid/ca.crt key=/etc/squid/ca.key ssl-bump sslproxy_cert_error allow all sslproxy_flags DONT_VERIFY_PEER

Note: SSL bumping is controversial as it creates a man-in-the-middle scenario—only use this if you fully control both client and server trust. For most cases, stick to standard HTTP proxies without SSL interception.

Load Balancing Multiple Proxies

For high availability, deploy multiple Squid instances behind a Google Cloud Load Balancer. Set up three instances in different zones, then create an HTTP(S) Load Balancer with a frontend IP and backend service pointing to all instances. This ensures redundancy—if one proxy fails, traffic automatically routes to others. Use health checks to monitor instance status and automatically remove unhealthy ones from the pool.

Troubleshooting Common Issues

Even with careful setup, issues can arise. Here's how to handle common problems:

1. Connection refused: Check if Squid is running (systemctl status squid). Verify firewall rules allow traffic on port 3128. Also confirm the client is using the correct IP and port.

2. Authentication failures: Ensure the htpasswd file is in the correct path and permissions (chmod 644 /etc/squid/passwd). Check squid.conf for correct auth_param settings.

3. Slow performance: Monitor CPU and network usage in GCE metrics. If overloaded, upgrade the instance type. For caching issues, check cache_dir settings and disk space.

4. SSL certificate errors: If using SSL bumping, ensure clients trust your CA certificate. Distribute the ca.crt file to all clients and import it into their trust store.

5. Logging not working: Ensure /var/log/squid/ has proper permissions (chown -R squid:squid /var/log/squid). Check disk space—if full, clear old logs or increase storage.

Conclusion

Setting up a proxy gateway on Google Cloud Compute Engine is a powerful way to control, secure, and optimize your network traffic. From basic Squid installation to advanced SSL termination and load balancing, the flexibility of GCE allows you to tailor the solution to your needs. Remember to prioritize security—limit access via firewall rules, enforce authentication, and regularly audit logs. As your requirements evolve, Google Cloud's ecosystem makes it easy to scale or integrate with other services like Cloud Storage for cache storage or Cloud Armor for DDoS protection. With this guide, you're now equipped to deploy a robust proxy gateway that stands up to real-world demands. Happy proxying!

TelegramContact Us
CS ID
@cloudcup
TelegramSupport
CS ID
@yanhuacloud