背景:做微信支付回调需要用到https域名,服务器是linux系统,用nginx做反向代理
准备:阿里云、腾讯云或者自己生成的SSL证书,java是8086端口
一:安装nginx,以前博客有记录
二:安装SSL模块
命令:首先1. cd /usr/local/nginx-1.19.9
2. ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
3. make
4. make install
三:将解压的证书放到/ssl文件夹下
证书可自己生成:私钥:openssl genrsa -out privkey.pem 2048
公钥: openssl req -new -x509 -key privkey.pem -out cacert.pem -days 1095
四:修改配置 /usr/local/nginx/conf/nginx.config中的server文件
开启443端口https默认端口
server {
listen 443 ssl http2;
server_name ***.***.cn;
ssl_certificate "/usr/local/nginx/ssl/***.***.cn.pem"; #换成自己的证书路径
ssl_certificate_key "/usr/local/nginx/ssl/***.***.cn.key"; #换成自己的证书路径
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://127.0.0.1:8086/; #换成自己Java程序的端口
}
}
server {
listen 80;
rewrite ^(.*)$ https://$host$1 permanent;#访问的http://ip会自动跳转到https://ip
}
五:效果