[英]Compressing assets with NGINX in reverse proxy mode
我正在将NGINX用作Node.js应用程序前面的反向代理。 基本代理可以正常工作,并且我可以使用compression
中间件来压缩Node服务器上的资产。
为了测试是否有可能将压缩任务委托给NGINX,我禁用了中间件,现在我尝试使用具有以下配置的NGINX gzip:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 300;
server {
listen 80;
## gzip config
gzip on;
gzip_min_length 1000;
gzip_comp_level 5;
gzip_proxied any;
gzip_vary on;
gzip_types text/plain
text/css
text/javascript
image/gif
image/png
image/jpeg
image/svg+xml
image/x-icon;
location / {
proxy_pass http://app:3000/;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_cache_bypass $http_upgrade;
}
}
}
使用此配置,NGINX不会压缩资产。 我尝试使用不同的选项在location
上下文中声明它们,但似乎没有一个可以解决问题。
我找不到与此相关的资源,所以我在质疑是否可以通过这种方式完成。
要点:
1- Node和NGINX位于不同的容器上,因此我不使用NGINX提供静态资产。 我只是代理到正在提供这些文件的节点服务器。 我要实现的所有工作都是通过让NGINX进行gzip压缩来卸载节点服务器。
2-我正在启用“ Accept-Encoding:gzip”的情况下测试所有响应。
尝试添加application/javascript
内容类型:
gzip_types
text/css
text/javascript
text/xml
text/plain
text/x-component
application/javascript
application/json
application/xml
application/rss+xml
font/truetype
font/opentype
application/vnd.ms-fontobject
image/svg+xml;
我从这个conf H5BP中获取了值:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.