Centos7 部署Nginx 及 调优
Nginx 官网下载: http://nginx.org/en/download.html
Nginx 搜狐镜像站:http://mirrors.sohu.com/nginx
最新的stable版本: http://nginx.org/download/nginx-1.18.0.tar.gz
镜像stable地址: http://mirrors.sohu.com/nginx/nginx-1.18.0.tar.gz
#!/bin/bash
yum install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
wget http://mirrors.sohu.com/nginx/nginx-1.18.0.tar.gz && tar -xf nginx-1.18.0.tar.gz
cd nginx-1.18.0/
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-stream --with-http_v2_module --with-http_gzip_static_module
make && make install
# Nginx 调优 开启 gzip 压缩
# 编译时载入模块 --with-http_gzip_static_module
gzip on;
gzip_proxied any;
gzip_vary on;
gzip_disable "MSIE [1-6]\.";
gzip_buffers 32 4k;
gzip_min_length 1k;
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-
php image/jpeg image/gif image/png application/vnd.ms-fontobject font/ttf font/opentype font/x-woff image/svg+xml;
gzip_comp_level 8;
# 加速 浏览器 缓存,适用静态页面
add_header Cache-Control "public";
add_header Cache-Control no-cache;
# SSL 兼容性设置
ssl_protocols TLSv1.2 TLSv1.1 TLSv1;
ssl_ciphers ECDHE-RSA-AES256-SHA384:AES256-SHA256:RC4:HIGH:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!AESGCM;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
# 80 转 443
server {
listen 80;
server_name www.域名.com;
if ($server_port !~ 443){
rewrite ^(/.*)$ https://$host$1 permanent;
}
}
不断学习