Can't enable nginx gzip on Elastic Beanstalk (Php, symfony)

1.2k Views Asked by At

I'm facing an issue with AWS Elastic Beanstalk(Php,Symfony) and gzip.

I'm trying to enable Gzip compression but it work only for .svg files with this configuration :

Folder hierarchy

nginx.config

server {
gzip on;
gzip_static on;
gzip_comp_level 6;
gzip_proxied any;
gzip_types text/html text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml;
gzip_min_length 1400;
}

symfony.config

location / {



try_files $uri $uri/ /index.php?$query_string;

gzip on;
gzip_vary on;
gzip_comp_level 6;
gzip_proxied any;
gzip_types text/html text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml;
gzip_min_length 1400;



if ($host !~* ^www\.) {
   return 301 https://www.$host$request_uri;
}

 if ($http_x_forwarded_proto != "https") {
      return 301 https://$host$request_uri;
 }
}



location ~* \.(?:ico|css|js|gif|jpe?g|png|svg)$ {
    expires 30d;
    add_header Pragma public;
    add_header Cache-Control "public";

    gzip_static on;
    gzip on;
    gzip_comp_level 4;
    gzip_types text/html text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml;


}

Is there any way to fix it ?

1

There are 1 best solutions below

0
firas.slimane On

Thanks to Marcin and Julien B it work now.

I changed the nginx directory to .platform/nginx/nginx.conf and get a default nginx config from the beanstalk instance, and set myconfig on it.

nginx.conf

#Elastic Beanstalk Nginx Configuration File

user                    nginx;
error_log               /var/log/nginx/error.log warn;
pid                     /var/run/nginx.pid;
worker_processes        auto;
worker_rlimit_nofile    65235;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    include       conf.d/*.conf;

    map $http_upgrade $connection_upgrade {
        default     "upgrade";
    }

    server {


        listen        80 default_server;
        access_log    /var/log/nginx/access.log main;

        client_header_timeout 60;
        client_body_timeout   60;
        keepalive_timeout     60;
        #gzip                  off;
        #gzip_comp_level       4;
        #gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;

        gzip on;
        gzip_static on;
        gzip_comp_level 6;
        gzip_proxied any;
        gzip_types application/javascript application/rss+xml application/vnd.ms-fontobject application/x-font application/x-font-opentype application/x-font-otf application/x-font-truetype application/x-font-ttf application/x-javascript application/xhtml+xml application/xml application/json font/opentype font/otf font/ttf image/svg+xml image/x-icon text/css text/html text/javascript text/plain text/xml;
        gzip_min_length 1400;


        # Include the Elastic Beanstalk generated locations
        include conf.d/elasticbeanstalk/*.conf;
    }

}