方法一:利用地址重写功能
server {
listen 80;
server_name www.etiantian.org;
rewrite ^(.*)$ https://$host$1 permanent;
}
说明:在https配置server基础上再添加http跳转server
方法二:利用error_page识别错误码信息进行跳转
server {
listen 443;
server_name www.etiantian.org;
ssl on;
ssl_certificate /application/nginx/conf/key/server.crt;
ssl_certificate_key /application/nginx/conf/key/server.key;
location / {
root html/www;
index index.html index.htm;
}
}
说明:497为内置错误码,当访问http无法处理,需要利用https处理时
利用反向代理服务器进行http到https跳转
1:修改地址池信息
upstream www_server_pools {
server 10.0.0.7:443;
server 10.0.0.8:443;
server 10.0.0.9:443;
}
2:修改地址池调用信息
server {
listen 443;
server_name www.etiantian.org;
ssl on;
ssl_certificate /application/nginx/conf/key/server.crt;
ssl_certificate_key /application/nginx/conf/key/server.key;
location / {
proxy_pass https://www_server_pools;
}
}
3:定义http到https跳转配置信息
server {
listen 80;
server_name www.etiantian.org;
rewrite ^(.*)$ https://$host$1 permanent;
}
原文地址:http://blog.51cto.com/11434174/2122719