-
Notifications
You must be signed in to change notification settings - Fork 800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added proxy_http_version 1.1 to nginx block conf to enable gzipping. #344
Conversation
@@ -58,6 +58,7 @@ if (!s.forceSsl || s.hasSsl) { | |||
proxy_set_header X-Real-IP $remote_addr; | |||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |||
proxy_set_header X-Forwarded-Proto $scheme; | |||
proxy_http_version 1.1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I understand, this is activating gzip for internal communication between two services on the same machine. It has nothing to do with gzipping between the client and the server. If my assumption is correct, this is not a good change, gzipping comes with CPU usage. The bandwidth that is being saved due to gzipping is the local bandwidth (within the server) which is quite cheap. So we are consuming CPU time for zipping and unzipping data on the same machine.
The captain ngnix acts like a proxy and a proxy does not process the message. You can test it out, I get a gzipped file at the client. |
I just re-tested it to be sure. And I am getting consistent result. Just to be clear, this is what I do:
The only added line is
Now to turn of gzip, all I need to do is to edit the config file to this:
Now the only changed line is
As you can see both responses are using HTTP 1.1, the presence of
I doubted my test results and repeated the test with Chrome, Curl and a third party website: https://checkgzipcompression.com/ All of them had the same result. I am very curious what technique did you use to test your configuration? |
Oh, okay now I now what you mean. I think I didn't showed that I want to use an ngnix as an app, so an ngnix in an ngnix. The outer ngnix should only load balance and SSL things. The inner ngnix should gzip etc. (because it's time and CPU consuming). Ngnix would only gzip on http1.1 and not on http1.0, so the outer ngnix should forward the http request with http1.1 and not with http1.0. I think a lot of implementations now rely on http1.1 and not http1.0 so this change should not only improve an ngnix in an ngnix. |
To wrap up:
Have a look at this: https://captainduckduck.com/img/captain-architecture.png The dark blue and the green line that connect end user to your server are using http 1.1 without any special instructions. I am closing this PR as it doesn't actually add gzip to the http block. You're more that welcome to open another PR and add a proper set of gzip instructions to this server block. Have a look at this post for example: https://www.keycdn.com/support/enable-gzip-compression |
Yes, you are right. But shouldn't be the lightblue inner communication http1.1 too? The nginx proxy conf says:
http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_http_version So the default value is http 1.0 and not 1.1. |
Nginx gzip only runs if the http version is 1.1.
Nginx proxy default makes the http version to 1.0.
You can change the
gzip_http_version 1.0
in your app, but I think it would be better to make it default to 1.1 withproxy_http_version 1.1
.