Introduction: Bypassing the GFW to Enjoy the Gemini API
For users in mainland China, accessing the Gemini API has always been hindered by the Great Firewall (GFW). Previously common methods of bypassing the GFW (such as setting up proxies) were not only cumbersome but also carried security risks. Cloudflare Pages/Workers and Deno, once highly recommended solutions, are no longer reliable due to policy changes or misuse issues. Cloudflare has explicitly prohibited the use of its platform for proxy services and has strengthened its blocking efforts, resulting in many user-built proxies becoming unusable. Deno, due to excessive use by mainland Chinese users overloading its servers, has begun restricting access from mainland China IP addresses.
After these methods became unavailable, I actively searched for new solutions. By chance, I discovered an article by Fobranski on "How to use Nginx reverse proxy for the Gemini API," which gave me great inspiration. After experimenting on my own server, I successfully built a working reverse proxy. To allow more people to easily replicate this success, I combined AI tools and personal experience to develop the GeminiProxy project.
Preparation
- An overseas server
- A valid Gemini API Key
- (Optional) A reliable VPN for initial server connection or network assistance in specific situations
Server Recommendation
If you don't already have a server, consider TimeCloud. They offer a US-based 2-2 50M uplink/downlink China Unicom AS9929 (China Unicom A network) server for only 20 RMB per month, and it uses a native IP address, making it ideal for setting up a proxy service.
I. Server Configuration and Connection
After purchasing your server, select "Reinstall System" on the product details page and choose a Debian-based operating system (such as Ubuntu). After confirming that your data has been backed up, click to start the reinstallation.
Once the system reinstallation is complete, you will need to use an SSH client to connect to your server. The following is a connection example (using the SSH service included with Ubuntu):
ssh root@your_server_ip
II. GeminiProxy Installation Script
After connecting to the server, enter the following command in the terminal to download and execute the installation script:
wget https://raw.githubusercontent.com/Cnfte/geminiproxy/refs/heads/main/proxy.sh && sudo bash proxy.sh
Press Enter, and the script will begin automatic installation.
III. Information Configuration and Domain Binding
During the installation process, you will see an interactive panel. Select "1" to start the configuration. The first installation may take some time, please be patient.
On the configuration page, you need to enter your domain name (e.g., yourdomain.com). Please ensure that you have pointed the A record of this domain to your server's IP address.
Domain Acquisition: If you don't have a domain name yet, you can consider registering a free dpdns.org domain at register.us.kg, valid for 180 days and renewable for free upon expiration.
SSL Certificate Application: You can apply for a free SSL certificate through okssl.com.cn.
Next, you need to configure the ports. For NAT servers, please ensure that the internal and external network ports are consistent. For example, if you bind the HTTP port to 12345 and the HTTPS port to 40443, you also need to open these two ports in the server control panel. When accessing, please use the format https://yourdomain.com:https_port.
Then, you need to provide the complete path to the SSL certificate:
- Certificate file (usually in
.pemformat) - Certificate key file (usually in
.keyformat)
After entering the above information, the script will start writing the configuration.
IV. Completion of Setup and Usage
At this point, your dedicated Gemini reverse proxy has been successfully set up! You only need to enter the configured domain name into your API request tool (such as Chatbox, etc.) to enjoy Gemini's services.
Important Note: Please use network proxy technology responsibly and refrain from creating any tools that violate the laws and regulations of mainland China.