Nginx出现The plain HTTP request was sent to HTTPS port

Nginx突然出现了下面的问题:

1
The plain HTTP request was sent to HTTPS port

在博客配置ssl证书的时候,博客的https地址和http地址是都能访问,不过,今天突然发现博客访问出现上面的问题,经过百度找到了问题的解决办法,在此记录一下。

解决办法:

删掉ssl on; 并在 listen 443; 443后加上ssl即可。
Nginx最新配置文件内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
server {
listen 80;
listen 443 ssl;

server_name www.ydstudio.net ydstudio.net;
set $my_server_name $scheme://$server_name;
root html;

if ($host = 'ydstudio.net') {
rewrite ^ https://www.ydstudio.net$request_uri? permanent;
}
#防止ip访问,如http://xxx.xxx.xxx.xxx或者https://xxx.xxx.xxx.xxx
if ( $host ~* "\d+\.\d+\.\d+\.\d+" ) {
rewrite ^ https://$server_name;
}

if ( $my_server_name != https://$server_name ) {
return 301 https://$server_name$request_uri;
#rewrite ^ https://$server_name$request_uri? permanent;
}

location / {
try_files $uri $uri/ /index.php$is_args$args;
index index.php index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
#root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME html/typecho/$fastcgi_script_name;
include fastcgi_params;
}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
#expires指令设置浏览器缓存过期时间
#可以在http、server、location三个作用域中设置
#缓存图片或视频30天
expires 30d;
}

location ~ .*\.(js|css)?$ {
#缓存js/css 1小时
expires 1h;
}

#ssl on;
ssl_certificate cert/214353452860792.pem;
ssl_certificate_key cert/214353452860792.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;
}
  • 作者: Sam
  • 发布时间: 2017-12-05 23:26:28
  • 最后更新: 2019-12-09 23:03:26
  • 文章链接: https://ydstudios.gitee.io/post/38efc407.html
  • 版权声明: 本网所有文章除特别声明外, 禁止未经授权转载,违者依法追究相关法律责任!