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的时候花括号需要对应好



