[英]gzip compression on AWS
我们如何在 AWS 上使用 docker 文件为 react js 应用程序启用 gzip 压缩? 我们希望为从服务器流向浏览器的工件启用 GZIP 压缩。 在 IIS 中我们已经使用了这样的设置。 但是我们不知道如何在 react js 的 Docker 文件中设置它。
您需要使用某种服务器来启用 gzip,就像在您之前使用 IIS 的情况下一样,我主要使用 Nginx 来启用 gzip,您可以从 Nginx 配置中执行此操作,但是为此,您必须使用 Nginx 基础映像来服务器 Reactjs应用程序。
这是 nginx 的 DockerFile
FROM node:10.15-alpine as build-stage
WORKDIR /app
COPY package*.json ./
RUN yarn
COPY ./ .
RUN yarn run build_prod
FROM nginx:1.17.6-alpine
RUN apk add --update --no-cache \
bash \
curl
#config nginx and supervisord
COPY ConfigFiles/nginx.conf /etc/nginx/nginx.conf
COPY ConfigFiles/site.conf /etc/nginx/sites-available/default.conf
RUN mkdir -p mkdir -p /etc/nginx/sites-enabled && \
mkdir -p /run/nginx && \
mkdir -p /var/www/frontend && \
ln -s /etc/nginx/sites-available/default.conf /etc/nginx/sites-enabled/default.conf
WORKDIR /var/www
#COPY dist ./frontend
COPY --from=build-stage /app/dist ./frontend
配置文件
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
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"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
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 font/opentype font/otf font/ttf image/svg+xml image/x-icon text/css text/javascript text/plain text/xml image/gif;
include /etc/nginx/sites-enabled/*.conf;
client_max_body_size 10M;
}
站点配置文件
server {
listen 80;
#server_name d;
root /var/www/frontend;
index index.html;
location / {
try_files $uri /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/frontend;
}
location ~ /\.ht {
deny all;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.