nginx怎么配置ssl可以即允许http访问也允许https访问

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx怎么配置ssl可以即允许http访问也允许https访问相关的知识,希望对你有一定的参考价值。

方法/步骤(只要不配置301或302跳转就可以了)
nginx配置SSL证书之后,https可以正常访问,http访问显示400错误,nginx的配置如下:
server
listen 80 default backlog=2048;
listen 443;
server_name wosign.com;
root /var/www/html;

ssl on;
ssl_certificate /usr/local/Tengine/sslcrt/ wosign.com.crt;
ssl_certificate_key /usr/local/Tengine/sslcrt/ wosign.com .key;

http访问的时候,报错如下:
400 Bad Request
The plain HTTP requset was sent to HTTPS port. Sorry for the inconvenience.
Please report this message and include the following information to us.
Thank you very much!

说是http的请求被发送到https的端口上去了,所以才会出现这样的问题。
2
server
listen 80 default backlog=2048;
listen 443 ssl;
server_name wosign.com;
root /var/www/html;

ssl_certificate /usr/local/Tengine/sslcrt/ wosign.com.crt;
ssl_certificate_key /usr/local/Tengine/sslcrt/ wosign.com .Key;

把ssl on;这行去掉,ssl写在443端口后面。这样http和https的链接都可以用,完美解决。
参考技术A 方法/步骤
给nginx配置SSL证书之后,https可以正常访问,http访问显示400错误,nginx的配置如下:
server
listen 80 default backlog=2048;
listen 443;
server_name wosign.com;
root /var/www/html;

ssl on;
ssl_certificate /usr/local/Tengine/sslcrt/ wosign.com.crt;
ssl_certificate_key /usr/local/Tengine/sslcrt/ wosign.com .key;

http访问的时候,报错如下:
400 Bad Request
The plain HTTP requset was sent to HTTPS port. Sorry for the inconvenience.
Please report this message and include the following information to us.
Thank you very much!

说是http的请求被发送到https的端口上去了,所以才会出现这样的问题。
2
server
listen 80 default backlog=2048;
listen 443 ssl;
server_name wosign.com;
root /var/www/html;

ssl_certificate /usr/local/Tengine/sslcrt/ wosign.com.crt;
ssl_certificate_key /usr/local/Tengine/sslcrt/ wosign.com .Key;

把ssl on;这行去掉,ssl写在443端口后面。这样http和https的链接都可以用,完美解决。
参考技术B 正常配置的ssl都是允许http和https共存的,除非做了强制https跳转——沃通(wosign)专业的数字证书CA机构

Nginx的加载失败的SSL证书问题,怎么解决

您好,加载失败可能WEB没有绑定准确,防火墙:443端口设置允许,测试本地服务器是否可以访问,SSL证书格式是否正确。 参考技术A

可能是没有正确配置吧,参考这个nginx ssl证书部署指南尝试一下。

以上是关于nginx怎么配置ssl可以即允许http访问也允许https访问的主要内容,如果未能解决你的问题,请参考以下文章

nginx怎么配置ssl可以即允许http访问也允许https访问

nginx怎么配置ssl可以即允许http访问也允许https访问

nginx配置ssl证书,允许ssl访问

怎么使用Nginx配置ssl实现https访问的方法

linux nginx ssl证书怎么配置

Nginx的加载失败的SSL证书问题,怎么解决