Nginx 자동 HTML 출력 축소


12

누구든지 즉시 HTML 출력을 최소화하기 위해 nginx (또는 다른 방법)를 얻는 방법을 알고 있습니까? 그것은 나에게 간단 해 보이며 몇 킬로바이트를 깎고 사이트 속도를 높일 수 있습니다.


3
이 기능이있는 확장 기능을 잘 모르겠지만 그만한 가치가 있습니까? 각 요청마다 CPU에 영향을 미치므로 부하가 증가함에 따라 웹 사이트에 더 많은 CPU가 필요합니다. 보내기 전에 텍스트를 압축하기 위해 이미 gzip 확장명을 사용하고 있다고 가정하므로 모든 공백은 해당 프로세스의 일부로 제거됩니다. 파일을 사전 gz 할 수 있으므로 각 요청에서 CPU 시간이 절약됩니다.
Andrew Taylor

@AndrewTaylor이므로 나중에 캐시하는 것이 좋습니다.
poige

답변:


2

Nginx 용 Google Pagespeed 는 축소 및 기타 여러 가지 작업을 수행합니다. 그러나 벤치 마크했을 때 내 사이트가 이미 잘 최적화되어 있기 때문에 귀찮게하는 데 충분한 차이가 없었습니다. 아직 최적화되지 않은 사이트의 경우 큰 차이가있을 수 있습니다.

Nginx / Pagespeed를 작동시키는 방법에 대한 튜토리얼이 있습니다 . 소스에서 빌드해야합니다. 해당 영역을 만지면 연결된 웹 사이트를 최신 상태로 유지하는 경향이 있으므로 아래의 답변보다 최신 정보 일 수 있습니다.

cd /home/ec2-user
mkdir nginx-build
cd nginx-build
service nginx stop
yum groupinstall "Development Tools"
yum install pcre-devel zlib-devel openssl-devel
wget http://nginx.org/download/nginx-1.9.11.tar.gz
wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz
wget https://github.com/openresty/headers-more-nginx-module/archive/v0.29.tar.gz
tar -xzf nginx-1.9.11.tar.gz
tar -xzf ngx_cache_purge-2.3.tar.gz
tar -xzf v0.29.tar.gz
tar -xzf 1.9.32.10.tar.gz    # Google Pagespeed, optional
ngx_version=1.9.32.10
wget https://github.com/pagespeed/ngx_pagespeed/archive/release-${ngx_version}-beta.zip   # Google Pagespeed, optional
cd ngx_pagespeed-release-1.9.32.10-beta   # Google Pagespeed, optional
wget https://dl.google.com/dl/page-speed/psol/${ngx_version}.tar.gz   # Google Pagespeed, optional
cd ../nginx-1.9.9
# Note that I have no idea what the next line does but it was in the official guide
PS_NGX_EXTRA_FLAGS="--with-cc=/opt/rh/devtoolset-2/root/usr/bin/gcc"
# Safe option, slower, lots of modules included
./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-threads --with-stream --with-stream_ssl_module --with-http_slice_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-http_v2_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic' --add-module=/tmp/ngx_cache_purge-2.3 --add-module=/tmp/headers-more-nginx-module-0.29 --with-http_realip_module --add-modeule=../ngx_pagespeed-release-1.9.32.10-beta
make && make install
make clean  (NB: optional)
service nginx start

12

내 권장 사항 : 최소화하고 gzip 모듈을 사용하십시오 . 더 잘 작동하고 동일한 목표를 달성합니다. 그러나 물론 할 수 있습니다. 있다 스트립라는 이름의 제 3 자 모듈은 특히이 주제에 대해.


gzip 구성 예 :

# Context:  http, server, location

    gzip            on;
    gzip_min_length 1000;
    gzip_proxied    expired no-cache no-store private auth;
    gzip_types      text/plain application/xml;

2
잘 찾았어요 그러나 프로덕션 준비가되지는 않았으므로 대신 gzip을 사용하는 것이 좋습니다 .HTML을 줄이는 것보다 훨씬 많은 비용을 절약합니다.
pjmorse

1
gzip_types과 같은 것을 더 추가하는 것을 잊지 마십시오 text/html.
Gerald

TLS / SSL에서 HTML 페이지의 gzip 압축은 BREACH에 취약 할 수 있습니다 .
Naglis
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.