springboot项目部署到nginx并支持https
一、nginx安装
首先g++、gcc、openssl-devel、pcre-devel和zlib-devel软件。
1、# yum install gcc-c++
源码编译需依赖gcc环境。
2、# yum install -y pcre pcre-devel
nginx的http模块使用pcre来解析正则表达式 。
3、# yum install -y zlib zlib-devel
zlib库提供了很多压缩和解压缩的方式,nginx用zlib对http包进行gzip。
4、# yum install -y openssl openssl-devel
openssl是一个安全套接字层密码库,nginx支持http协议和https协议(在ssl协议上传输http)。
5、nginx官网网址下载http://nginx.org/en/download.html安装包nginx-1.12.2.tar.gz
6、将文件解压到/usr/local/目录下# tar -zxvf nginx-1.12.2.tar.gz
7、# cd nginx-1.12.2
8、./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
9、make && make install 编译与安装
10、访问http:IP看是否出现欢迎nginx页面,出现则成功
11、修改配置文件使其支持https.修改conf目录下的nginx.conf
1)server_name填写域名
2)rewrite为重定向到https
3)server_name填写域名
4)ssl两项为ssl证书,可在腾讯云免费申请得到
12)进入nginx的sbin目录下重启./nginx -s reload
13)访问https://ip看是否出现欢迎界面
二、部署springboot项目
1)打包springboot项目为jar包,并启动
nohup java -Dfile.encoding=utf-8 -jar ./test.jar >test.file 2>&1 &
2)修改nginx配置文件,通过nginx转发至springboot服务上
proxy_pass为springboot项目地址
3)重启nginx。./nginx -s reload。此时可以使用https访问项目了。
复制资源:
proxy_pass http://ip:8080;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;