I. Introduction
Detailed tutorial on Baota's anti-openai official API interface to solve the problem of using ChatGPT+502 Bad Gateway in China.
This method is the simplest and fastest, has no complicated steps, and is not prone to errors. It is the simplest, zero-code, zero-deployment method.
2. Prerequisites for realization
- An overseas VPS server
- OpenAI official API_KEY
- Third-party website systems or plug-ins
Regarding third-party website systems or plug-ins , you can read another article for introduction, download, deploy and use:
https://www.idcyli.com/33.htmlhttps://www.idcyli.com/33.html
3. Implementation process
The overseas server used here has a general configuration. If you only build the reverse generation interface of ChatGPT, the configuration does not need to be very high.
Step 1: Use the Pagoda panel to create a new site - bind your own domain name - select pure static - confirm and submit
Step 2: Configure the SSL certificate for the domain name. Here you can use the free certificate that comes with Pagoda.
Enable SSL secure access
Step 3: Add and configure reverse proxy
Among them, the target address fills in the official API address of openai: https://api.openai.com, and the sending domain name is also: api.openai.com, which will be obtained automatically.
Step 4: Access Test
When accessing the anti-generation address, 502 Bad Gateway appears.
Reason: The reason for the SSL certificate is that when SSL is turned on, it does not match during the three-way handshake, causing the handshake to fail!
Step 5: Solve the problem of 502 Bad Gateway when accessing
Add the code in the configuration file of the direction agent
First line of code:
proxy_ssl_server_name on;
Second line of code:
proxy_ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
Step 6: Test the API
You can see that our own anti-generation API interface is the same as the official one.
4. Use
Generate API KEY
Enter openai's api official website, https://platform.openai.com/account/api-keys, and create KEY
Configure docking API
Connect to third-party website systems or plug-ins
Test use
The AI system built here is a domestic server, and the network is a local domestic network. The usage effect is
About the tutorial:
I have written the original tutorials in April and May 2023. One of the tutorials written in April has been deleted. Many bloggers directly copied it without writing the source. The key Nginx problem with 502 Bad Gateway was also not written out . Settings For a paid solution, here is a complete tutorial.
5. Summary
The method used here is the reverse proxy function that comes with Pagoda, which is a normal method. Using SSL, you have to solve the problem of Nginx three-way handshake.