https其实就是在http应用层的基础上加上一层tls/ssl协议(安全传输层协议)。保证网站数据的安全可靠传输

http 和 https 的不同之处

  1. http 的 URL 以 http:// 开头,而 https 的 URL 以 https:// 开头
  2. http 是不安全的,而 https 是安全的
  3. http 标准端口是 80 ,而 https 的标准端口是 443
  4. 在 OSI 网络模型中,http 工作于应用层,而 https 工作在传输层
  5. http 无需加密,而 https 对传输的数据进行加密
  6. http 无需证书,而 https 需要认证证书

https实现

启动 https 网站,用nginx永久重定向到 https 网站的端口

server {
    listen 80;
    server_name kelen.cc www.kelen.cc;
    # 永久重定向到https下
    return 301 https://www.kelen.cc$request_uri; 
}

# https服务
server {
    listen 443 ssl;
    server_name kelen.cc www.kelen.cc;
    root html;
    index index.html index.htm;
    ssl_certificate   "/home/XXX.pem";
    ssl_certificate_key  "/home/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;
    location / {
        # https
        proxy_pass https://127.0.0.1:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
    # serve static files
    location ~ ^/(images|javascript|js|css|flash|media|static)/  {
        root    127.0.0.1:8080/;
        expires 30d;
    }
}

 

本文为原创,未经授权,禁止任何媒体或个人自媒体转载
商业侵权必究,如需授权请联系[email protected]
标签: nginx