background:
Recently, I was debugging the chatgpt dialogue website. Because the returned data is relatively large, stream reading is used. There is no problem at all in calling http, but when you switch to https in production, you always get an error? This problem has been entangled for 2 days, and finally solved with your chatgpt blessing
Why does HTTPS return a large paragraph, while HTTP returns line by line?
This is becausehttps
the andhttp
protocols use different transport methods when transferring data.http
The protocol uses plaintext transmission, and the data is transmitted line by line, and each line of data ends with a carriage return and a line feed. This transmission method is relatively simple, but it is not secure enough, and it is easy to be eavesdropped and tampered with.https
The protocol uses encrypted transmission, and the data is transmitted in large sections, and the length of each piece of data is not fixed. This transmission method is relatively safe and can protect the confidentiality and integrity of data, but compared withhttp
the protocol, the transmission efficiency will be slightly lower. Therefore, if you need to transmit data with high confidentiality, it is recommended to usehttps
the protocol for transmission. If the data you need to transmit is less confidential, you can use
http
the protocol for transmission.
How to modify the nginx configuration if https is to be changed to return line by line?
If you want to change the data return method under the HTTPS protocol to return line by line, you can do so by modifying the configuration file of Nginx.
In the Nginx configuration file, you can control the caching and transmission of data through proxy_buffering
and proxy_buffer_size
these two parameters. By default, Nginx will enable caching, cache data in memory, and then transmit it to the client at one time. If you want to transmit data line by line to the client, you can set proxy_buffering
the parameter to a small value, eg . Here is an example configuration file:off
proxy_buffer_size
1
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /path/to/cert.pem;
ssl_certificate_key /path/to/key.pem;
location / {
proxy_pass http://backend;
proxy_buffering off;
proxy_buffer_size 1;//这个实际作用不大,可以注销掉
}
}
In this example configuration file, we proxy_buffering
set the parameter to off
, and proxy_buffer_size
set the parameter to 1
, so that the data can be transmitted to the client line by line. At the same time, we also enabled the HTTPS protocol and specified the path of the SSL certificate and private key.
After the final configuration, nginx reloads the configuration
nginx -s reload
Full support for hhttps, you can register an account to try it out, contact me if you know me, and get a free one-month membership, https://yizhan.club