原创

nginx强制http跳转https

nginx 强制从http跳转到https,配置如下

server {
      listen       80;
      server_name  xxx.com www.xxx.com;
      rewrite ^(.*) https://$server_name$1 permanent;
    }

    server {
      listen       443;
      server_name  xxx.com www.xxx.com;
      ssl          on;

      location /{ 
            proxy_pass http://127.0.0.1:9000; 
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
             client_max_body_size     16m;
             client_body_buffer_size  256k;
             proxy_connect_timeout    1200;
             proxy_read_timeout       1200;
             proxy_send_timeout       6000;
             proxy_buffer_size        32k;
             proxy_buffers        4 64k;
             proxy_busy_buffers_size 128k;
             proxy_temp_file_write_size 128k;
    }

      ssl_certificate   /usr/local/nginx/xxx.pem;
      ssl_certificate_key  /usr/local/nginx/xxx.key;
      ssl_session_timeout 5m;
      ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
      ssl_ciphers AESGCM:ALL:!DH:!EXPORT:!RC4:+HIGH:!MEDIUM:!LOW:!aNULL:!eNULL;
      ssl_prefer_server_ciphers on;   

    }

server_name xxx.com www.xxx.com 自己的域名
ssl_certificate /usr/local/nginx/xxx.pem; 阿里云免费生成的ssl证书文件
ssl_certificate_key /usr/local/nginx/xxx.key; 阿里云免费生成的ssl证书文件密钥
rewrite ^(.*) https://$server_name$1 permanent; 重写输入的域名

正文到此结束
Loading...