服务器使用Nginx如何部署Springboot项目

发布时间:2020-07-02 14:46:28 作者:清晨
来源:亿速云 阅读:686

这篇文章将为大家详细讲解有关服务器使用Nginx如何部署Springboot项目,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

1,将java项目打成jar包

这里我用到的是maven工具

服务器使用Nginx如何部署Springboot项目

这里有两个项目,打包完成后一个为demo.jar,另一个为jst.jar

2.准备工具

1.服务器
2.域名(注:经过备案)
3.Xshell用于连接服务器
4.WinScp(注:视图工具,用于传输jar)

3.将jar包传入服务器

服务器使用Nginx如何部署Springboot项目

直接拖动即可

3.使用Xshell运行jar包

注:(服务器的java环境以及maven环境,各位请自行配置,这里不做描述。)

服务器使用Nginx如何部署Springboot项目

cd到jar包路径下执行:nohup java -jar demo.jar >temp.txt &
执行启动完两个jar包后使用ip与端口号访问接口

服务器使用Nginx如何部署Springboot项目

(注:测试接口)

4.下载安装nginx

安装教程

5.配置nginx.conf

**(注:*********代表服务器地址)

http {
  include    mime.types;
  default_type application/octet-stream;

  #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  #         '$status $body_bytes_sent "$http_referer" '
  #         '"$http_user_agent" "$http_x_forwarded_for"';

  #access_log logs/access.log main;

  sendfile    on;
  #tcp_nopush   on;

  #keepalive_timeout 0;
  keepalive_timeout 65;

  #gzip on;
 
  server {
   #监听的端口号
    listen   80;
    #设置访问的二级域名
    server_name demo.eysource.com;

    #charset koi8-r;

    #access_log logs/host.access.log main;

    location /{
    #配置访问的项目路径(注:这里重点)
    proxy_pass http:********:9091/
    # root html;
    # index index.html index.htm;
    proxy_set_header      Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header      X-Forwarded-For    $proxy_add_x_forwarded_for;
    client_max_body_size 100m;
    root  html;
    index index.html index.htm;
     }
   }
  server {
   #监听的端口号
    listen   80;
    #设置访问的二级域名
    server_name aaa.eysource.com;

    #charset koi8-r;

    #access_log logs/host.access.log main;

    location /{
    #配置访问的项目路径(注:这里重点)
    proxy_pass http:********:8080/
    # root html;
    # index index.html index.htm;
    proxy_set_header      Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header      X-Forwarded-For    $proxy_add_x_forwarded_for;
    client_max_body_size 100m;
    root  html;
    index index.html index.htm;
     }
   }
 }

6通过域名访问(成功)

服务器使用Nginx如何部署Springboot项目

关于服务器使用Nginx如何部署Springboot项目就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

推荐阅读:
  1. nginx下如何部署vue项目
  2. Docker如何部署springboot项目

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

服务器 nginx springboot

上一篇:linuxip无法ping通的解决方法

下一篇:Linux常用命令都有哪些

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》