admin管理员组

文章数量:1026444

I've got some pressed javascript files being served by nginx:

<script type="application/javascript" src="js/shim.min.js.gz"></script>
<script type="application/javascript" src="js/zone.js.gz"></script>

but it appears that nginx is serving them as text/plain resulting in browser errors:

SyntaxError: illegal character   shim.min.js.gz:1

Looking at the headers, this is the response:

Content-Encoding:gzip
Content-Type:text/plain
Date:Tue, 29 Nov 2016 18:03:01 GMT
ETag:W/"583ce194-68b3"
Last-Modified:Tue, 29 Nov 2016 02:01:56 GMT 
Server:nginx/1.10.2
Vary:Accept-Encoding

Here is my nginx.conf:

worker_processes 4;

events { worker_connections 1024; }

http {
include /etc/nginx/mime.types;

gzip on;
gzip_static on;
gzip_disable "msie6";

gzip_vary on;
gzip_p_level 5;
gzip_buffers 16 8k;
gzip_http_version 1.0;
gzip_min_length 256;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript application/vnd.ms-fontobject application/x-font-ttf font/opentype image/svg+xml image/x-icon;

        upstream node-app {
              server node1:3000 weight=10 max_fails=3 fail_timeout=30s;
        }

        server {
              listen 80;
              index index.html
              error_log  /var/log/nginx/error.log;
              access_log /var/log/nginx/access.log;
              root /var/www/public;

              location /api {
                proxy_pass http://node-app;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;
              }
        }
}

I have gzip_static set to on but it doesn't appear to be working. I am using the nginx docker image:

>nginx:1.10.2-alpine

This image is piled with the gzip static module:

--with-http_gzip_static_module

if I unpress the javascripts and serve them unpressed everything works fine. Is there an issue with the mime types? This works fine with:

<script type="application/javascript" src="js/shim.min.js"></script>
<script type="application/javascript" src="js/zone.js"></script>

I've got some pressed javascript files being served by nginx:

<script type="application/javascript" src="js/shim.min.js.gz"></script>
<script type="application/javascript" src="js/zone.js.gz"></script>

but it appears that nginx is serving them as text/plain resulting in browser errors:

SyntaxError: illegal character   shim.min.js.gz:1

Looking at the headers, this is the response:

Content-Encoding:gzip
Content-Type:text/plain
Date:Tue, 29 Nov 2016 18:03:01 GMT
ETag:W/"583ce194-68b3"
Last-Modified:Tue, 29 Nov 2016 02:01:56 GMT 
Server:nginx/1.10.2
Vary:Accept-Encoding

Here is my nginx.conf:

worker_processes 4;

events { worker_connections 1024; }

http {
include /etc/nginx/mime.types;

gzip on;
gzip_static on;
gzip_disable "msie6";

gzip_vary on;
gzip_p_level 5;
gzip_buffers 16 8k;
gzip_http_version 1.0;
gzip_min_length 256;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript application/vnd.ms-fontobject application/x-font-ttf font/opentype image/svg+xml image/x-icon;

        upstream node-app {
              server node1:3000 weight=10 max_fails=3 fail_timeout=30s;
        }

        server {
              listen 80;
              index index.html
              error_log  /var/log/nginx/error.log;
              access_log /var/log/nginx/access.log;
              root /var/www/public;

              location /api {
                proxy_pass http://node-app;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;
              }
        }
}

I have gzip_static set to on but it doesn't appear to be working. I am using the nginx docker image:

>nginx:1.10.2-alpine

This image is piled with the gzip static module:

--with-http_gzip_static_module

if I unpress the javascripts and serve them unpressed everything works fine. Is there an issue with the mime types? This works fine with:

<script type="application/javascript" src="js/shim.min.js"></script>
<script type="application/javascript" src="js/zone.js"></script>
Share Improve this question asked Nov 29, 2016 at 19:35 code4causecode4cause 1291 silver badge9 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

Module ngx_http_gzip_static_module:

The ngx_http_gzip_static_module module allows sending prepressed files with the “.gz” filename extension instead of regular files.

gzip_static:

Enables (“on”) or disables (“off”) checking the existence of prepressed files.

We have to have two files for supported pression clients (/some/path/js/filename.js.gz) and not supported (/some/path/js/filename.js).

The files can be pressed using the gzip mand, or any other patible one.

Use in your html:

<script type="application/javascript" src="/js/filename.js"></script>

and nginx will return to the client one of the files.

It is remended that the modification date and time of original and pressed files be the same.

I've got some pressed javascript files being served by nginx:

<script type="application/javascript" src="js/shim.min.js.gz"></script>
<script type="application/javascript" src="js/zone.js.gz"></script>

but it appears that nginx is serving them as text/plain resulting in browser errors:

SyntaxError: illegal character   shim.min.js.gz:1

Looking at the headers, this is the response:

Content-Encoding:gzip
Content-Type:text/plain
Date:Tue, 29 Nov 2016 18:03:01 GMT
ETag:W/"583ce194-68b3"
Last-Modified:Tue, 29 Nov 2016 02:01:56 GMT 
Server:nginx/1.10.2
Vary:Accept-Encoding

Here is my nginx.conf:

worker_processes 4;

events { worker_connections 1024; }

http {
include /etc/nginx/mime.types;

gzip on;
gzip_static on;
gzip_disable "msie6";

gzip_vary on;
gzip_p_level 5;
gzip_buffers 16 8k;
gzip_http_version 1.0;
gzip_min_length 256;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript application/vnd.ms-fontobject application/x-font-ttf font/opentype image/svg+xml image/x-icon;

        upstream node-app {
              server node1:3000 weight=10 max_fails=3 fail_timeout=30s;
        }

        server {
              listen 80;
              index index.html
              error_log  /var/log/nginx/error.log;
              access_log /var/log/nginx/access.log;
              root /var/www/public;

              location /api {
                proxy_pass http://node-app;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;
              }
        }
}

I have gzip_static set to on but it doesn't appear to be working. I am using the nginx docker image:

>nginx:1.10.2-alpine

This image is piled with the gzip static module:

--with-http_gzip_static_module

if I unpress the javascripts and serve them unpressed everything works fine. Is there an issue with the mime types? This works fine with:

<script type="application/javascript" src="js/shim.min.js"></script>
<script type="application/javascript" src="js/zone.js"></script>

I've got some pressed javascript files being served by nginx:

<script type="application/javascript" src="js/shim.min.js.gz"></script>
<script type="application/javascript" src="js/zone.js.gz"></script>

but it appears that nginx is serving them as text/plain resulting in browser errors:

SyntaxError: illegal character   shim.min.js.gz:1

Looking at the headers, this is the response:

Content-Encoding:gzip
Content-Type:text/plain
Date:Tue, 29 Nov 2016 18:03:01 GMT
ETag:W/"583ce194-68b3"
Last-Modified:Tue, 29 Nov 2016 02:01:56 GMT 
Server:nginx/1.10.2
Vary:Accept-Encoding

Here is my nginx.conf:

worker_processes 4;

events { worker_connections 1024; }

http {
include /etc/nginx/mime.types;

gzip on;
gzip_static on;
gzip_disable "msie6";

gzip_vary on;
gzip_p_level 5;
gzip_buffers 16 8k;
gzip_http_version 1.0;
gzip_min_length 256;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript application/vnd.ms-fontobject application/x-font-ttf font/opentype image/svg+xml image/x-icon;

        upstream node-app {
              server node1:3000 weight=10 max_fails=3 fail_timeout=30s;
        }

        server {
              listen 80;
              index index.html
              error_log  /var/log/nginx/error.log;
              access_log /var/log/nginx/access.log;
              root /var/www/public;

              location /api {
                proxy_pass http://node-app;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;
              }
        }
}

I have gzip_static set to on but it doesn't appear to be working. I am using the nginx docker image:

>nginx:1.10.2-alpine

This image is piled with the gzip static module:

--with-http_gzip_static_module

if I unpress the javascripts and serve them unpressed everything works fine. Is there an issue with the mime types? This works fine with:

<script type="application/javascript" src="js/shim.min.js"></script>
<script type="application/javascript" src="js/zone.js"></script>
Share Improve this question asked Nov 29, 2016 at 19:35 code4causecode4cause 1291 silver badge9 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

Module ngx_http_gzip_static_module:

The ngx_http_gzip_static_module module allows sending prepressed files with the “.gz” filename extension instead of regular files.

gzip_static:

Enables (“on”) or disables (“off”) checking the existence of prepressed files.

We have to have two files for supported pression clients (/some/path/js/filename.js.gz) and not supported (/some/path/js/filename.js).

The files can be pressed using the gzip mand, or any other patible one.

Use in your html:

<script type="application/javascript" src="/js/filename.js"></script>

and nginx will return to the client one of the files.

It is remended that the modification date and time of original and pressed files be the same.

本文标签: javascriptgzipstatic not working with nginxStack Overflow