找回密码
 立即注册

Nginx 自动跳转到HTTPS Nginx设置http自动跳转https SSL配置

[复制链接]
发表于 2020-4-24 16:29:52 | 显示全部楼层 |阅读模式
安卓上架
Nginx 自动跳转到HTTPS Nginx设置http自动跳转https SSL配置

1.方法一
  1. rewrite ^(.*)$ https://$host$1 permanent;
复制代码


2.方法二
适用于 80端口和443 配置在同一个 server{}内
  1. if ($server_port = 80) {
  2.       rewrite ^(.*)$ https://$host$1 permanent;
  3. }
复制代码


其他情况, 站点绑定很多域名,只让某个域名跳转:
  1. set $redirect_https 1;
  2. if ($server_port = 80) {
  3.    set $redirect_https "${redirect_https}2";
  4. }
  5. if ($http_host = 'www.yourdomain.com') {
  6.    set $redirect_https "${redirect_https}3";
  7. }
  8. if ($http_host = 'yourdomain.com') {
  9.    set $redirect_https "${redirect_https}3";
  10. }

  11. if ($redirect_https = "123") {
  12. rewrite ^(.*)$ https://$host$1 permanent;
  13. }
复制代码


示例
  1. server {
  2.         listen       80;
  3.         server_name  www.getssl.cc;
  4.         rewrite ^ https://$http_host$request_uri? permanent;
  5. }

  6. server {
  7.         listen 443;
  8.         ssl on;
  9.         ssl_certificate /etc/ssl/cacert.pem;
  10.         ssl_certificate_key /etc/ssl/privkey.pem;
  11.         server_name www.getssl.cn;  

  12.        
  13.         server_tokens off;

  14.         location / {
  15.           
  16.                 fastcgi_param   HTTPS               on;
  17.                 fastcgi_param   HTTP_SCHEME         https;

  18.         }
  19.        
  20. }
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|一门开发者社区 ( 蜀ICP备17005078号-4 )

GMT+8, 2025-5-1 18:34 , Processed in 0.048384 second(s), 19 queries .

Powered by Discuz! X3.5

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表