环境要 nignx 模块 安装 http_ssl_module http_v2_module
本环境使用了https http 2.0 配置
查看nginx 配置安装模块
nginx -V
configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module --with-openssl=/data/package/lnmp1.4-full/src/openssl-1.0.2l --add-module=/data/package/nginx-http-concat
1、80端口配置
server {
listen 80;
server_name www.example.com;
return 301 https://$server_name$request_uri;
}
80 强制跳转 https环境
2、
443端口配置
server {
listen 443 ssl http2;
root /data/www/static;
server_name www.example.com;
ssl on;
ssl_session_timeout 5m;
ssl_protocols TLSv1.2;
ssl_certificate /usr/local/nginx/conf/ssl/a_bundle.crt;
ssl_certificate_key /usr/local/nginx/conf/ssl/a.key;
location ~ .*\.(js|css|png|jpg|gif)$ {
if (-f $request_filename) {
expires 30d;
break;
}
}
loation /api {
rewrite ^~api/?(.*)$ /$1 break;
proxy_pass https://api.example.com;
}
location /{
add_header Cache-Control no-cache,no-store,must-revalidate;
try_files $uri $uri/ /index.html;
}
# nginx-http-concat 合并js/css使用
location /h5-static {
concat on;
concat_max_files 15;
concat_types text/css application/javascript;
}}
重启命令 nginx -s reload