how to get nginx to gzip all files and add an expires header
From http://wiki.nginx.org/HttpGzipModule
gzip on;
gzip_min_length 1000;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain application/xml;
gzip_disable "MSIE [1-6]\.";
From http://wiki.nginx.org/HttpHeadersModule
expires 24h;
expires modified +24h;
expires @15h30m;
expires 0;
expires -1;
expires epoch;
add_header Cache-Control private;
It appears that some of these options exist inside of your phpmyadmin area but not in your main website config.
Related videos on Youtube
Deb
She/Her, DevOps & Systems Engineering. I do monitoring and telemetry. I read manuals. Also: author of Software Telemetry so I guess I write them too now.
Updated on September 18, 2022Comments
-
Deb almost 2 years
recently got into VPS systems and installing them, and all that blah blah etc etc. So, I have a couple working websites, and on one of them I'm trying to really optimize it for speed. Using Yahoo's ySlow as a guide, I am still failing the gzip and header expires sections. My nginx.conf is located in /etc/nginx/nginx.conf, and here is its details:
PLEASE HELP! i have no idea why it isn't working.
####################################################################### # # This is the main Nginx configuration file. # # More information about the configuration options is available on # * the English wiki - http://wiki.codemongers.com/Main # * the Russian documentation - http://sysoev.ru/nginx/ # ####################################################################### #---------------------------------------------------------------------- # Main Module - directives that cover basic functionality # # http://wiki.codemongers.com/NginxMainModule # #---------------------------------------------------------------------- user www www; worker_processes 2; error_log /var/log/nginx/error.log; #error_log /var/log/nginx/error.log notice; #error_log /var/log/nginx/error.log info; pid /var/run/nginx.pid; #---------------------------------------------------------------------- # Events Module # # http://wiki.codemongers.com/NginxEventsModule # #---------------------------------------------------------------------- events { worker_connections 1024; } #---------------------------------------------------------------------- # HTTP Core Module # # http://wiki.codemongers.com/NginxHttpCoreModule # #---------------------------------------------------------------------- http { include /etc/nginx/mime.types; default_type application/octet-stream; client_max_body_size 10M; client_body_buffer_size 128k; log_format main ' - [] ' '"" "" ' '"" ""'; access_log /var/log/nginx/access.log main; sendfile on; tcp_nopush on; keepalive_timeout 20; tcp_nodelay on; # Load config files from the /etc/nginx/conf.d directory include /etc/nginx/conf.d/*.conf; # # The default server # server { listen 443; server_name 127.0.0.2; ssl on; ssl_certificate /etc/nginx/sslconf/server.crt; ssl_certificate_key /etc/nginx/sslconf/server.key; location /phpmyadmin { root /usr/html; index index.php; gzip on; gzip_http_version 1.1; gzip_vary on; gzip_comp_level 6; gzip_proxied any; gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript text/x-js; gzip_buffers 16 8k; location ~* \.(jpg|png|gif|jpeg|css|js)$ { expires 1h; } } location ~ \.php$ { include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/html$fastcgi_script_name; fastcgi_param HTTPS on; } } server { listen 80; server_name 127.0.0.2; #charset koi8-r; #access_log logs/host.access.log main; location / { root /usr/html; index index.html index.htm index.php; } location = /phpmyadmin/ { rewrite ^ https://127.0.0.2$uri redirect; } error_page 404 /404.html; location = /404.html { root /usr/html; } # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/html$fastcgi_script_name; } #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # location ~ /\.ht { deny all; } } # Load virtual host configuration files. include /etc/nginx/sites-enabled/*; }
-
Admin about 12 yearsThanks for your reply Aaron, and pardon me for being such a newbie..but how do I take your reply and make my VPS gzip all files and add expire headers?