Enable gzip in Nginx without specifying the http directive is not allowed here "error
I have inherited a code base that requires gzip. I added these lines to the nginx staging.conf file (which shows up in two other places: / etc / nginx / sites-enabled / and / etc / nginx / sites-available /):
But when I try to restart nginx it fails (without any error message) and running "sudo nginx" gives me this error:
nginx: [emerg] "http" directive is not allowed here in /etc/nginx/sites-enabled/staging.conf:37
This is the whole conf file:
I tried to put the http block after the server blocks and before the server blocks, and I tried to put the server blocks in the http block, but none of these things worked. I get the same problem on my production server (the production.conf file looks pretty much the same except without the "stagingpy" subdomain). I have also tried to bring gzip-line from http bloc as a whole, and it has caused this error when you run "sudo nginx could":
nginx: [emerg] "gzip" directive is duplicate in /etc/nginx/sites-enabled/staging.conf:38
; however, I don't see any other gzip lines when I look at the file in this path.
Where should the http block be so that I can successfully restart nginx and enable gzip to compress the file?
Edit: I also tried to create a gzip.conf file in conf.d as shown here , but even after I removed the http block from the staging.conf file, I got an error stating that gzip is a duplicate (
nginx: [emerg] "gzip" directive is duplicate in /etc/nginx/conf.d/gzip.conf:1
). This makes me think that gzip is already in the conf file, but running
find /etc/nginx/ -type f -name "*.conf" | grep gzip -n
it only gives me the gzip.conf file. According to some online gzip tests, the site has gzip, but others say it doesn't.
source to share
It looks like there is another nginx.conf file that I didn't know about (don't know why it didn't show up when running find) that has gzip in it, and hence a recurring error. After checking my site on several other sites (for example, http://www.whatsmyip.org/http-compression-test/ ), it turns out that http://checkgzipcompression.com/ is incorrect about the site not compressing. I'm not sure why Google PageSpeed still offers compression, but that as far as I could get it.
source to share