溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

服務(wù)器使用Nginx如何部署Springboot項(xiàng)目

發(fā)布時(shí)間:2020-07-02 14:46:28 來源:億速云 閱讀:703 作者:清晨 欄目:開發(fā)技術(shù)

這篇文章將為大家詳細(xì)講解有關(guān)服務(wù)器使用Nginx如何部署Springboot項(xiàng)目,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

1,將java項(xiàng)目打成jar包

這里我用到的是maven工具

服務(wù)器使用Nginx如何部署Springboot項(xiàng)目

這里有兩個(gè)項(xiàng)目,打包完成后一個(gè)為demo.jar,另一個(gè)為jst.jar

2.準(zhǔn)備工具

1.服務(wù)器
2.域名(注:經(jīng)過備案)
3.Xshell用于連接服務(wù)器
4.WinScp(注:視圖工具,用于傳輸jar)

3.將jar包傳入服務(wù)器

服務(wù)器使用Nginx如何部署Springboot項(xiàng)目

直接拖動(dòng)即可

3.使用Xshell運(yùn)行jar包

注:(服務(wù)器的java環(huán)境以及maven環(huán)境,各位請(qǐng)自行配置,這里不做描述。)

服務(wù)器使用Nginx如何部署Springboot項(xiàng)目

cd到j(luò)ar包路徑下執(zhí)行:nohup java -jar demo.jar >temp.txt &
執(zhí)行啟動(dòng)完兩個(gè)jar包后使用ip與端口號(hào)訪問接口

服務(wù)器使用Nginx如何部署Springboot項(xiàng)目

(注:測(cè)試接口)

4.下載安裝nginx

安裝教程

5.配置nginx.conf

**(注:*********代表服務(wù)器地址)

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 {
   #監(jiān)聽的端口號(hào)
    listen   80;
    #設(shè)置訪問的二級(jí)域名
    server_name demo.eysource.com;

    #charset koi8-r;

    #access_log logs/host.access.log main;

    location /{
    #配置訪問的項(xiàng)目路徑(注:這里重點(diǎn))
    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 {
   #監(jiān)聽的端口號(hào)
    listen   80;
    #設(shè)置訪問的二級(jí)域名
    server_name aaa.eysource.com;

    #charset koi8-r;

    #access_log logs/host.access.log main;

    location /{
    #配置訪問的項(xiàng)目路徑(注:這里重點(diǎn))
    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通過域名訪問(成功)

服務(wù)器使用Nginx如何部署Springboot項(xiàng)目

關(guān)于服務(wù)器使用Nginx如何部署Springboot項(xiàng)目就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI