本文介绍vps基于nginx的web服务器的配置。
安装java环境
yum install java
wget http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo -O /etc/yum.repos.d/epel-apache-maven.repo
yum -y install apache-maven
配置nginx反向代理springboot启动的应用
- DNS解析配置A标记
- vps上通过
java -jar webapp.jar
启动基于springboot的应用,本地默认会启动监听8080的http服务 - 配置server,在
/etc/nginx/conf.d/
下添加webapp.conf
文件
server配置如下:
upstream api.suninf.net {
server localhost:8080;
}
server {
listen 80;
server_name api.suninf.net;
location / {
proxy_pass http://api.suninf.net;
proxy_redirect default;
}
}
springboot应用的https化配置
申请证书
需要先停止之前的服务,然后选择执行如下命令,选择cert的临时服务申请证书:
certbot certonly --agree-to -d api.suninf.net
server配置更新
upstream api.suninf.net {
server localhost:8080;
}
server {
listen 443 ssl;
server_name api.suninf.net;
ssl_certificate /etc/letsencrypt/live/api.suninf.net/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/api.suninf.net/privkey.pem;
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
location / {
proxy_pass http://localhost:8080
proxy_redirect http://localhost:8080 https://api.suninf.net;
}
}