现在的网站支持https几乎是标配功能,nginx能很好的支持https功能。下面列举一个配置同时支持http和https的功能。
需要注意的是:既然选择使用https,就是为了保证通信安全,那么就没必要再用http进行通信了。在url中还支持http的方式,主要是为了用户不知道网站支持https,还是使用http的方式进行访问。这时nginx后台需要自动将http请求转成https的方式,这样就又能支持http,又能保证通信安全了。
废话不多说,下面直接贴一个nginx支持http和https的配置,是我的wordpres网站支持https的配置,大家何以参考。
server { # 开启https listen 443 ssl; # 配置证书,免费证书怎么申请这边就不多说了。在晚上搜索腾讯云或者阿里云免费证书申请即可 ssl_certificate /etc/nginx/conf.d/cert/4351595_www.xxx.pem; ssl_certificate_key /etc/nginx/conf.d/cert/4351595_www.xxx.key; ssl_session_timeout 5m; ssl_ciphers ecdhe-rsa-aes128-gcm-sha256:ecdhe:ecdh:aes:high:!null:!anull:!md5:!adh:!rc4; ssl_protocols tlsv1 tlsv1.1 tlsv1.2; ssl_prefer_server_ciphers on; server_name xxx; index index.htm index.php; root /data/wwwroot/wordpress; error_log /var/log/nginx/wordpress-error.log crit; access_log /var/log/nginx/wordpress-access.log; # 这边用于包含其他配置 include extra/*.conf; include conf.d/rewrite/wordpress.conf; } # 将http请求转化成https请求 server { listen 80; server_name xxx; rewrite ^/(.*) https://$server_name$request_uri? permanent; }
到此这篇关于nginx同时支持http和https的配置详解的文章就介绍到这了,更多相关nginx同时支持http和https配置内容请搜索移动技术网以前的文章或继续浏览下面的相关文章希望大家以后多多支持移动技术网!
如对本文有疑问, 点击进行留言回复!!
网友评论