为什么使用https协议?
使用http协议大都面临以下问题:
- 网站页面会被篡改,非法跳转
- 网站被植入广告
https协议是由SSL+HTTP协议构建的可进行加密传输、身份认证的网络协议,要比http协议安全,可防止数据在传输过程中不被窃取、改变,确保数据的完整性。
HTTPS是现行架构下最安全的解决方案,虽然不是绝对安全,但它大幅增加了中间人攻击的成本。
Nginx配置
- http
# 将http的所有请求进行重定向到https
server {
listen 80;
server_name localhost;
rewrite ^(.*)$ https://$host$1 permanent;
}
- https
# 基本上使用nginx默认的配置
server {
listen 443 ssl;
server_name localhost;
ssl_certificate cert.pem;
ssl_certificate_key cert.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_protocols TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
# 将nginx的请求重定向到本地服务
location /index {
proxy_pass http://127.0.0.1:9999;
proxy_redirect off;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 600;
proxy_read_timeout 600;
proxy_send_timeout 600;
}
}
需要注意的问题
- 云服务器控制台需要配置对应的
80
与443
端口 - https的配置文件中需要修改自己申请的
CA证书
文件路径 - 修改配置后需要重启nginx
网友评论