Vote count: 0
I've inherited a code base that needs gzip enabled. I added these lines to my nginx staging.conf file (which shows up in two more places: /etc/nginx/sites-enabled/ and /etc/nginx/sites-available/):
http {
# enable gzip compression
gzip on;
gzip_min_length 1100;
gzip_buffers 4 32k;
gzip_types text/plain application/x-javascript text/xml text/css;
gzip_vary on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
# end gzip configuration
}
But when I try to restart nginx, it fails (without any error message), and running "sudo nginx" gets me this error: nginx: [emerg] "http" directive is not allowed here in /etc/nginx/sites-enabled/staging.conf:37
This is the entire conf file:
# Myexample staging nginx setup. This is meant to be included in /etc/nginx/sites-available.
ssl_certificate /home/django/http://ift.tt/1K2us26;
ssl_certificate_key /home/django/http://ift.tt/1yMuzOh;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH+aRSA+RC4 EECDH EDH+aRSA !RC4 !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS";
server {
listen 80;
listen 443 ssl;
server_name http://ift.tt/1K2us28;
return 301 $http://ift.tt/1yMuCcV;
}
server {
listen 80;
listen 443 ssl;
server_name stagingpy.myexample.io;
access_log /var/log/nginx/myexample_access.log;
error_log /var/log/nginx/myexample_error.log;
location ^~ /apple-touch-icon { root /home/django/http://ift.tt/1K2us2a; expires 1h; }
location = /favicon.ico { root /home/django/http://ift.tt/1K2us2a; expires 1h; }
location = /humans.txt { root /home/django/http://ift.tt/1yMuCta; expires 1h; }
location = /robots.txt { root /home/django/http://ift.tt/1yMuCta; expires 1h; }
location /static/ { root /home/django/myexample.io/ ; expires 30d; }
location / {
uwsgi_pass unix:///var/run/uwsgi/app/staging/socket;
include uwsgi_params;
}
}
http {
# enable gzip compression
gzip on;
gzip_min_length 1100;
gzip_buffers 4 32k;
gzip_types text/plain application/x-javascript text/xml text/css;
gzip_vary on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
# end gzip configuration
}
I've tried putting the http block after the server blocks and before the server blocks, and I've tried putting the server blocks into the http block, but none of these things have worked. I get the same problem on my production server (the production.conf file looks pretty much the same, except without the "stagingpy" subdomain).
Where should the http block go so that I can restart nginx successfully and have gzip enabled for file compression?
Enable gzip on Nginx without "'http' directive is not allowed here" error
Aucun commentaire:
Enregistrer un commentaire