nginx中如何配置ssl证书及springboot项目

##red##
🔴
大家好,我是雄雄,欢迎关注微信公众号,雄雄的小课堂。

前言

每次发布新项目,都要去宝塔里面把原来的nginx配置信息拷贝过来,然后在改改,这次在这边做个记录

ssl证书的配置

1.这种是多个域名直接指向一个地址的

##博客项目
     server {
        listen       80;
        listen       443 ssl http2;
        server_name  xxx.com;
        gzip on;
         gzip_vary on;
         gzip_comp_level 9;
         gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
         gzip_disable "MSIE [1-6]\.";
       gzip_min_length 2048;
        
        if ($server_port !~ 443){
            rewrite ^(/.*)$ https://$host$1 permanent;
        }
        
        #证书地址
        ssl_certificate      /home/project/https/xxx.com.team_bundle.pem;
        ssl_certificate_key   /home/project/https/xxx.com.team.key;
        ssl_prefer_server_ciphers on;
 
       location / {
            root   /home/project/blog/web/web/dist;
            index  index.html index.htm;
            try_files $uri $uri/ /index.html;
        }
        
        location /admin {
            alias   /home/project/blog/web/admin/dist;
            index  index.html index.htm;
            try_files $uri $uri/ /index.html;
        }
        
        #公众号小游戏
        location /games {
            alias   /home/project/blog/web/games/fxq;
            index  index.html index.htm;
            try_files $uri $uri/ /index.html;
        }
       
        ##后台接口
        location ^~ /shiyi/ {
            proxy_pass http://127.0.0.1:8800;
            proxy_connect_timeout 300s;
            proxy_send_timeout 300s;
            proxy_read_timeout 300s;
        }
        
        ##内网穿透
        location ^~ /shiyi-local/ {
            ##proxy_pass http://127.0.0.1:6000/shiyi/;
            proxy_connect_timeout 300s;
            proxy_send_timeout 300s;
            proxy_read_timeout 300s;
        }
        
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
    ## server结束

2.这种是单个域名指向一个前端文件

##博客项目
     server {
        listen       80;
        listen       443 ssl http2;
        server_name  xxx.com;
        gzip on;
         gzip_vary on;
         gzip_comp_level 9;
         gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
         gzip_disable "MSIE [1-6]\.";
       gzip_min_length 2048;
        
        if ($server_port !~ 443){
            rewrite ^(/.*)$ https://$host$1 permanent;
        }
        
        #证书地址
        ssl_certificate      /home/project/https/88688.xxx.com.pem;
        ssl_certificate_key   /home/project/https/xxx.com.team.key;
        ssl_prefer_server_ciphers on;
 
       location / {
            root   /home/project/blog/web/web/dist;
            index  index.html index.htm;
            try_files $uri $uri/ /index.html;
        }
        
        location /admin {
            alias   /home/project/blog/web/admin/dist;
            index  index.html index.htm;
            try_files $uri $uri/ /index.html;
        }
        
        #公众号小游戏
        location /games {
            alias   /home/project/blog/web/games/fxq;
            index  index.html index.htm;
            try_files $uri $uri/ /index.html;
        }
       
        ##后台接口
        location ^~ /shiyi/ {
            proxy_pass http://127.0.0.1:8800;
            proxy_connect_timeout 300s;
            proxy_send_timeout 300s;
            proxy_read_timeout 300s;
        }
        
        ##内网穿透
        location ^~ /shiyi-local/ {
            ##proxy_pass http://127.0.0.1:6000/shiyi/;
            proxy_connect_timeout 300s;
            proxy_send_timeout 300s;
            proxy_read_timeout 300s;
        }
        
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
    ## server结束

3.这种得是crt文件和pem文件


##小鱼早晚安打卡小程序
     server {
        listen       80;
        listen       443 ssl http2;
        server_name  xcx.xxx.com.team;
        
        if ($server_port !~ 443){
            rewrite ^(/.*)$ https://$host$1 permanent;
        }
        
        #证书地址
        ssl_certificate      /home/project/blog/https/fullchain.crt;
        ssl_certificate_key   /home/project/blog/https/private.pem;
        ssl_prefer_server_ciphers on;
 
        location / {
            root   /home/project/blog/web/web/dist;
            index  index.html index.htm;
            try_files $uri $uri/ /index.html;
        }
        
        location /admin {
            alias   /home/project/blog/web/admin/dist;
            index  index.html index.htm;
            try_files $uri $uri/ /index.html;
        }
        ##后台接口
        location ^~ /shiyi/ {
            proxy_pass http://127.0.0.1:8800;
            proxy_connect_timeout 300s;
            proxy_send_timeout 300s;
            proxy_read_timeout 300s;
            
        }
    }   


普通http的配置


 ##机器人服务端
     server {
        listen       80;
        server_name  bot.xxx.com.team;
        
       location / {
          root /home/project/wechatbot/dist;
    			try_files $uri $uri/ /index.html;
          index  index.html index.htm;
      }
          
      location ^~ /prod-api/ {
    			proxy_pass http://127.0.0.1:8900/;
    			proxy_connect_timeout 300s;
    			proxy_send_timeout 300s;
    			proxy_read_timeout 300s;
    	}
    	 #词云地址
        location /ciyun {
            alias   /home/project/fastapi/ciyun;
            index  index.html index.htm;
            try_files $uri $uri/ /index.html;
        }
       }

##green##
🟢
至此,就over啦!

要在Linux上部署Spring Boot项目,可以使用Nginx作为代理服务器来实现。 首先,确保你已经在Linux服务器上安装了Java运行环境和Spring Boot项目的JAR文件。接下来,你需要确保Nginx已经安装并运行。你可以使用包管理工具,如apt-get或yum,在Linux上安装Nginx。 安装完成后,你需要在Nginx配置文件添加一个新的虚拟主机来处理Spring Boot应用程序的请求。打开Nginx的主配置文件,一般位于/etc/nginx/nginx.conf,并找到"server"块。 在该块,添加以下配置代码: ``` server { listen 80; # 监听的端口 server_name example.com; # 你的域名 location / { proxy_pass http://localhost:8080; # 转发到Spring Boot应用程序的端口 proxy_set_header Host $host; } } ``` 将"example.com"替换为你的域名。这个配置将监听80端口,并将所有的请求转发到本地的Spring Boot应用程序的8080端口。proxy_set_header配置将Host头信息设置为请求的原始主机,这样Spring Boot应用程序可以正确识别来自Nginx的请求。 保存并关闭配置文件后,重新启动Nginx服务以使更改生效: ``` sudo service nginx restart ``` 现在,当用户访问你的域名时,Nginx将会将请求转发给Spring Boot应用程序。你可以使用日志记录来确保一切正常。你还可以通过配置SSL证书来启用HTTPS,以增强安全性。 这是部署Spring Boot项目的一个简单方法。你可以根据自己的需求进行更复杂的配置,例如负载均衡或缓存设置。希望对你有所帮助!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

穆雄雄

哎,貌似还没开张来着呢~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值