我是靠谱客的博主 霸气荷花,这篇文章主要介绍winServer服务器搭建nginx配置https问题及流程:,现在分享给大家,希望可以做个参考。

问题:

1、 配置切记要仔细,每个配置项最后都应以_ ; _结尾。报错如下:

复制代码
1
2022/07/11 12:51:29 [emerg] 3284#4856: "worker_processes" directive is not allowed here in F:nginx/conf/conf.d/nginx(1).conf:3

2、配置文件中配置文件名与实际路径下文件名不一致。报错如下:

复制代码
1
2
3
4
5
2022/07/11 12:52:49 [emerg] 4504#2412: cannot load certificate "F:nginx/conf/ssl/mpatrol.cn_bundle.pem": BIO_new_file() failed (SSL: error:02001002:system library:fopen:No such file or directory:fopen('F:nginx/conf/ssl/mpatrol.cn_bundle.pem','r') error:2006D080:BIO routines:BIO_new_file:no such file) 问题修复过程:    1、刚开始以为是winServer不支持绝对路径配置,然后修改为绝对路径,问题依然存在。    2、将证书相关两文件放置conf文件目录下测试相对路径与绝对路径,问题依然存在。    3、最终发现拷贝文件与配置中文件名不一致,修改一致后,问题修复。

3、nginx版本不同,配置项有所改动:(非问题,作为记录防止遗忘)

1.15及以后版本都不在支持ssl on;

复制代码
1
2
老版本nginx配置https使用:ssl on;  开启ssl属性。 新版本nginx配置https使用:listen 443 ssl; 即可开启ssl属性。

4、400 Bad Request: The plain HTTP request was sent to HTTPS port

复制代码
1
2
3
4
从报错的字面意思上来看,是因为HTTP请求被发送到HTTPS端口,这种报错多出现在Nginx既处理HTTP请求又处理HTTPS请求的情况。 该项目nginx中配置了http server模块和https server模块,具体业务流向为:    https -> http: 访问登陆页后跳转详情页 由于配置不完善导致登陆成功后跳转详情页时,未能正常将所有的HTTP请求重定向到HTTPS导致页面异常。
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; proxy_pass http://0.0.0.0:8082; proxy_redirect http:// https://;   # 将http协议转为https协议 ​ 解读:    1)proxy_pass执行前,先设置了request head host 为https外网访问的域名+端口    2)proxy_pass执行后,tomcat结果返回response 3)proxy_redirect修改response中的location中的协议http为https外网访问的协议。    java redirect重定向主要是通过访问tomcat服务的请求head项来决定的,默认是http协议,域名是通过读取host地址,默认host中不包括访问端口,因此使用非443端口时,访问web地址时需添加端口。

当前项目主要配置项:在https server模块下添加http重定向https。

复制代码
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
server {    listen       81;    listen       8087 ssl;    server_name          www.XXX.cn XXX.cn;    ssl_protocols        TLSv1 TLSv1.1 TLSv1.2;    ssl_ciphers          AES128-SHA:AES256-SHA:RC4-SHA:DES-CBC3-SHA:RC4-MD5;    ssl_certificate      ssl/XX.cn_bundle.crt;    ssl_certificate_key  ssl/XX.cn.key;    ssl_session_cache    shared:SSL:10m;    ssl_session_timeout  15m;    ssl_prefer_server_ciphers  on; ​    location / {        root   html/mpis;        index  index.html;   }    location /cc/web/ {        proxy_pass http://0.0.0.0:10002/mpis/web/;   }    location /cc/base/ {        proxy_pass http://0.0.0.0:10001/mpis/base/;   }      location /hxdlhd {        proxy_pass http://www.XXXX.cn:81/hxdlhd/login/goLogin;        proxy_set_header  X-Real-IP  $remote_addr;        proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;        proxy_set_header X-Forwarded-Proto https;        proxy_set_header Host $http_host;   }    location /hxdlhd/ {        proxy_pass http://0.0.0.0:8080/hxdlhd/;        proxy_set_header  X-Real-IP  $remote_addr;        proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;        proxy_set_header X-Forwarded-Proto https;        proxy_set_header Host $http_host;                # 配置此属性即可完成 http重定向至https        proxy_redirect http:// https://; ​   }    location ~* ^/WW_verify_h3vxzGabbQ7SLsWm.txt {        default_type text/html;        alias F://nginx-1.21.6/html/WW_verify_h3vxzGabbQ7SLsWm.txt;   }     }

最后

以上就是霸气荷花最近收集整理的关于winServer服务器搭建nginx配置https问题及流程:的全部内容,更多相关winServer服务器搭建nginx配置https问题及流程内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(90)

评论列表共有 0 条评论

立即
投稿
返回
顶部