單臺web服務器實現http訪問自動跳轉到https:

方法一:利用地址重寫功能
server {
listen 80;
server_name www.etiantian.org;
rewrite ^(.*)$ https://$host$1 permanent;
}
說明:在https配置server基礎上再添加http跳轉serverhtml

方法二:利用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處理時nginx

利用反向代理服務器進行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;
}app

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;
}
}ide

3:定義http到https跳轉配置信息
server {
listen 80;
server_name www.etiantian.org;
rewrite ^(.*)$ https://$host$1 permanent;
}代理

相關文章
相關標籤/搜索