#nginx 版本1.18.0
upstream myserver_01 {
server 127.0.0.1:8080 max_fails=1 fail_timeout=60;
}
upstream myserver_02 {
server x.x.x.x:8080 max_fails=1 fail_timeout=60;
}
server {
listen 80;
server_name test.test.com;
# gzip config
gzip on;
gzip_min_length 1k;
gzip_comp_level 9;
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;
gzip_vary on;
gzip_disable "MSIE [1-6]\.";
rewrite ^(.*)$ https://$host$1;
root /home/ymbl/front/apps;
location / {
# 用于配合 browserHistory 使用
try_files $uri $uri/ /index.html;
# 如果有资源,建议使用 https + http2,配合按需加载可以获得更好的体验
# rewrite ^/(.*)$ https://preview.pro.loacg.com/$1 permanent;
}
location /api/ {
proxy_pass http://127.0.0.1:8080/;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
}
}
#以下属性中,以ssl开头的属性表示与证书配置有关。
server {
listen 443 ssl;
#配置HTTPS的默认访问端口为443。
#如果未在此处配置HTTPS的默认访问端口,可能会造成Nginx无法启动。
#如果您使用Nginx 1.15.0及以上版本,请使用listen 443 ssl代替listen 443和ssl on。
server_name test.test.com; #需要将yourdomain.com替换成证书绑定的域名。
index index.html index.htm;
ssl_certificate /usr/local/nginx/conf/cert/test/test.test.com.pem; #需要将cert-file-name.pem替换成已上传的证书文件的名称。
ssl_certificate_key /usr/local/nginx/conf/cert/test/test.test.com.key; #需要将cert-file-name.key替换成已上传的证书私钥文件的名称。
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
#表示使用的加密套件的类型。
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3; #表示使用的TLS协议的类型。
ssl_prefer_server_ciphers on;
# gzip config
gzip on;
gzip_min_length 1k;
gzip_comp_level 9;
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;
gzip_vary on;
gzip_disable "MSIE [1-6]\.";
set $black myserver_02;
set $fe_root /home/test/app/apps;
if ($http_cookie ~* "version=V1"){
set $black myserver_01;
set $fe_root /home/test/app/apps-pre;
}
if ($http_cookie ~* "version=V2"){
set $black myserver_02;
}
root $fe_root;
location / {
## 配置页面不缓存html和htm结尾的文件
if ($request_filename ~* .*\.(?:htm|html)$) {
add_header Cache-Control "private, no-store, no-cache, must-revalidate, proxy-revalidate";
}
index index.html index.htm;
# 用于配合 browserHistory 使用
try_files $uri $uri/ /index.html;
# 如果有资源,建议使用 https + http2,配合按需加载可以获得更好的体验
# rewrite ^/(.*)$ https://preview.pro.loacg.com/$1 permanent;
}
location ~ /api/(.*) {
proxy_pass http://$black/$1;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_send_timeout 3600;
proxy_read_timeout 3600;
proxy_connect_timeout 3600;
}
#location ~ .*\.(htm|html)?$ {
#现在改为,增加缓存
# add_header Cache-Control " no-store";
#}
}