栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

linux中nginx配置https

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

linux中nginx配置https

centos 7
在http主体找到#HTTPS server行,把下一行的server注释去掉,在主体中加入一下内容

server {
        listen       80 ssl;
        server_name  localhost;#可为域名

        ssl_certificate      证书路径 .pem文件;
        ssl_certificate_key   秘钥路径 .key文件;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

#        location / {
#            root   html;
#            index  index.html index.htm;
#		}
	location /aa {
		if ($request_method !~ ^(POST|GET)$){
                 return 404;
		 }
        proxy_pass http://localhost:8080/aa;
		}
	location /abc {
		if ($request_method !~ ^(POST|GET)$){
                 return 404;
        proxy_pass http://localhost:8080/abc;
        }
}

上面的意思就是在浏览器中输入域名或者ip地址,nginx会把域名转发到对应的路由上去。
本人的是从https://localhost:80/aa/ 转发到 http://localhost:8080/aa

问题出现

1、如果是win下的nginx,加证书需要注意反斜杠,因为有的反斜杠遇到特定的字符时会被转译,例如:

ssl_certificate    E:nginxcertxxxxxx.pem;
ssl_certificate_key    E:nginxcertxxxxxxx.key;

上面的路径就会被反斜杠转译,单查看日志的时候会发现报错是这样的:

cannot load certificate "E:ginxcertxxxxxx.pem": BIO_new_file() failed (

结果是n被反斜杠转译了,可以使用\来访问E:nginxcertxxxxxx.pem,因为在文件系统中\是被宽容的
2、如果是在linux中部署的,加证书以及配置的时候需要注意在这个配置当中应该是http,不是https。以及增加location的时候花括号需要对应好

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/881901.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号