不会自动跳转的配置
server {
listen 80;
listen 443 ssl;
server_name 你自己的域名;
charset utf-8;
ssl on;
ssl_certificate server.crt;
ssl_certificate_key server.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
access_log logs/access.log;
root 你自己的项目路径例如 "D:/apache-tomcat-7.0.56/webapps/test";
# 在server块添加以下代砿
# 设置默认倿
set $uid "-";
# 存在值则赋倿
if ( $http_cookie ~* "at_uvid=(\S+)(;.*|$)"){
set $uid $1;
}
# log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for" "$uid"';
location ^~ /stolt {
proxy_pass http://localhost:9000/test;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-real-ip $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
break;
}
}
修改为如下 分开配置 配置自动跳转
server{
listen 80;
server_name 你自己的域名;
rewrite ^(.*) https://$server_name$1 permanent; #跳转
}
server {
listen 443 ssl;
server_name 你自己的域名;
charset utf-8;
ssl on;
ssl_certificate server.crt;
ssl_certificate_key server.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
access_log logs/access.log;
root 你自己的项目路径例如 "D:/apache-tomcat-7.0.56/webapps/test";
# 在server块添加以下代砿
# 设置默认倿
set $uid "-";
# 存在值则赋倿
if ( $http_cookie ~* "at_uvid=(\S+)(;.*|$)"){
set $uid $1;
}
# log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for" "$uid"';
location ^~ /stolt {
proxy_pass http://localhost:9000/test;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-real-ip $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
break;
}
}
分开配置 即可 http自动跳转https