原来我用 vertx 创建了一个 https apiserver, 想着用 nginx 反向代理一下. 证书是阿里云上免费一年的.
后来发现 nginx 要反向代理 https 自己也必须是 https. 这样我索性把 vertx 的 ssl 去掉了. 直接用 nginx 的.
我的 nginx 的配置文件在 / etc/nginx, 可以用 whereis nginx 查看.
从阿里云下载证书 for nginx
1. 在目录下创建 cert 目录, 并且将下载的全部文件拷贝到 cert 目录中.
2. 修改配置文件
- [java] view plain https://blog.csdn.net/zyydecsdn/article/details/80317999# copy https://blog.csdn.net/zyydecsdn/article/details/80317999#
- server {
- listen 443 ssl;
- server_name www.zyyapp.com;
- ssl_certificate cert/2146842898821.pem;
- ssl_certificate_key cert/214684289890721.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;
- location / {
- # root html;
- # index index.html index.htm;
- proxy_pass https://127.0.0.1:8080;
- ### force timeouts if one of backend is died ##
- proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
- ### Set headers ####
- proxy_set_header Host $host;
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- ### Most PHP, Python, Rails, Java App can use this header ###
- proxy_set_header X-Forwarded-Proto https;
- ### By default we don't want to redirect it ####
- proxy_redirect off;
- }
- }
3.nginx -t 查看是否正确
4. 如果是 centos 7 的话可以 systemctl restart nginx 重启 nginx
来源: http://www.bubuko.com/infodetail-2619118.html