TLDR
- Issue:Unable to receive SSE after migrating Nginx configuration from test to production environment
- Cause:Nginx 1.22.0 defaults to using HTTP/1.0 instead of HTTP/1.1
- Investigation : Enable debug logs and analyze
- Solution : Specify HTTP version 1.1 in Nginx global settings
Scenario
After migrating the same configuration from the test environment to the production environment, regular requests worked normally, but SSE had no response (Timeout).
Manual and tool comparisons, as well as ChatGPT analysis, did not reveal any configuration issues. The only difference was that the test environment used Nginx version 1.22.1, while the production environment used version 1.22.0.
Investigation
Enable Debug Logs
First, enable debug logs in /etc/nginx/nginx.conf
to print detailed errors:
|
|
Check the configuration and reload Nginx:
|
|
Analyze Logs
We can find error information in /var/log/nginx/error.log
.
For urgent online fixes with many users online, which may result in too many logs to search through, you can use the following command:
|
|
This command will continuously track the latest line of error.log
and filter out lines containing “sse”.
Then, trigger the problematic API and obtain the following information:
|
|
Discovering the Problem
Upon closer inspection, we can see in the last line that Nginx did not correctly apply the HTTP/1.1 setting and erroneously used HTTP/1.0, causing the SSE transmission to fail.
Even setting proxy_http_version 1.1;
in all places in the configuration did not successfully resolve the issue.
It is speculated that for unknown reasons (possibly version differences), Nginx ignored the configuration file and used the default HTTP/1.0 to call SSE.
Solution
Directly change the global proxy_http_version
default to 1.1 in the http block.
This forces Nginx to use HTTP/1.1 in all connections, including connections to upstream servers.
|
|
Conclusion
- Version differences can lead to unexpected issues, even with identical configuration files.
- Enabling detailed logs is very helpful for diagnosing problems.
- Sometimes global settings can solve specific problems, especially when individual directives seem ineffective.
- When migrating environments, be sure to carefully check the versions of all related software.