1.前言
最近在优化网站的访问速度,为网站开启http2协议,这个协议有什么优点呢?如下:
2.准备工作
3.操作步骤
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| cd /usr/local/src
wget https://www.openssl.org/source/openssl-1.0.2t.tar.gz
tar -zxvf openssl-1.0.2t.tar.gz
cd openssl-1.0.2t
./config shared zlib
make && make install
mv /usr/bin/openssl /usr/bin/openssl.old mv /usr/include/openssl /usr/include/openssl.old
ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl ln -s /usr/local/ssl/include/openssl /usr/include/openssl
echo "/usr/local/ssl/lib" >> /etc/ld.so.conf
ldconfig -p
openssl version
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| cd /usr/local/src
wget http://tengine.taobao.org/download/tengine-2.2.2.tar.gz
tar tengine-2.2.2.tar.gz
cd tengine-2.2.2
vim auto/lib/openssl/conf
CORE_INCS="$CORE_INCS $OPENSSL/.openssl/include" CORE_DEPS="$CORE_DEPS $OPENSSL/.openssl/include/openssl/ssl.h" CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libssl.a" CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libcrypto.a"
CORE_INCS="$CORE_INCS $OPENSSL/include" CORE_DEPS="$CORE_DEPS $OPENSSL/include/openssl/ssl.h" CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libssl.a" CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libcrypto.a"
yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel gcc gcc-c++ autoconf automake jemalloc jemalloc-devel
cd /usr/local/src/tengine-2.2.2 && ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-http_concat_module --with-jemalloc --with-http_v2_module --with-http_secure_link_module --with-openssl=/usr/local/ssl make
make install
cp -af /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx_bak cp -af /usr/local/nginx/sbin/dso_tool /usr/local/nginx/sbin/dso_tool_bak
cp /usr/local/src/tengine-2.2.2/objs/nginx /usr/local/nginx/sbin/ cp /usr/local/src/tengine-2.2.2/objs/dso_tool /usr/local/nginx/sbin/
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| server { listen 80 listen 443 ssl http2; server_name www.oneq.work; ..... }
upstream server_backend {
server ip:80 weight=10;
server ip:80 weight=10;
keepalive 800;
check interval=5000 rise=3 fall=3 timeout=5000 type=tcp; }
server { listen 80; listen 443 ssl http2; server_name xxx.xxx.xxx;
req_status server;
ssl_certificate /usr/local/nginx/certs/xxx.xxx.xxx.crt; ssl_certificate_key /usr/local/nginx/certs/xxx.xxx.xxx.key; ssl_session_timeout 5m; ssl_protocols TLSv1.1 TLSv1.2 TLSv1; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on;
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_pass_header User-Agent; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Connection ""; proxy_http_version 1.1; access_log logs/access.log main;
location / { proxy_pass http://server_backend/; access_log logs/server_backend.log main; }
error_page 404 /404.html; location = /404.html { root html; }
error_page 500 502 503 504 /50x.html;
location = /50x.html { root html; } }
|
4.效果展示

5.总结
1.第一次安装tengine和升级步骤有所区别,需要注意下
2.http不支持http2的传输协议,所以80端口还是使用http1.1的协议,https使用http2的传输协议