最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Nginx部署SpringBoot項(xiàng)目的實(shí)現(xiàn)

 更新時(shí)間:2023年03月03日 16:04:32   作者:默默前行的蝸牛  
本文主要介紹了Nginx部署SpringBoot項(xiàng)目的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

筆記記錄一下用Nginx部署SpringBoot項(xiàng)目

1、新建一個(gè)yml文件 application.yml

# 端口號(hào)
server:
  port: 2001

2、編寫(xiě)一個(gè)Controler測(cè)試類

package com.example.demo1.controller;


import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Component
@RequestMapping("/v1")
public class HelloController {
?? ?final static Logger log = LogManager.getLogger(HelloController.class);
?? ?@Value("${server.port}")
?? ?private int port ;

?? ?@RequestMapping(value = "", method = RequestMethod.GET)
?? ?public String test() {
?? ??? ?return "invoke url /,port="+port;
?? ?}

?? ?@RequestMapping(value = "/test1", method = RequestMethod.GET)
?? ?public String test1() {
?? ??? ?return "invoke url /test1,port="+port;
?? ?}

?? ?@RequestMapping(value = "/test2", method = RequestMethod.GET)
?? ?public String test2() {
?? ??? ?return "invoke url /test2,port="+port;
?? ?}
}

3、編寫(xiě)一個(gè)啟動(dòng)類

package com.example.demo1;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Demo1Application {

?? ?public static void main(String[] args) {
?? ??? ?SpringApplication.run(Demo1Application.class, args);
?? ?}
}

4、我用到的pom文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
? ? ? ? ?xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
? ? <modelVersion>4.0.0</modelVersion>
? ? <parent>
? ? ? ? <groupId>org.springframework.boot</groupId>
? ? ? ? <artifactId>spring-boot-starter-parent</artifactId>
? ? ? ? <version>2.7.6</version>
? ? ? ? <relativePath/> <!-- lookup parent from repository -->
? ? </parent>
? ? <groupId>com.example</groupId>
? ? <artifactId>demo1</artifactId>
? ? <version>0.0.1-SNAPSHOT</version>
? ? <name>demo1</name>
? ? <description>Demo project for Spring Boot</description>
? ? <properties>
? ? ? ? <java.version>1.8</java.version>
? ? ? ? <log4j.version>2.19.0</log4j.version>
? ? </properties>
? ? <dependencies>
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>org.springframework.boot</groupId>
? ? ? ? ? ? <artifactId>spring-boot-starter</artifactId>
? ? ? ? </dependency>
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>org.springframework.boot</groupId>
? ? ? ? ? ? <artifactId>spring-boot-starter-web</artifactId>
? ? ? ? ? ? <!--?? ??? ??? ?<exclusions>-->
? ? ? ? ? ? <!--?? ??? ??? ??? ?<exclusion>-->
? ? ? ? ? ? <!--?? ??? ??? ??? ??? ?<groupId>ch.qos.logback</groupId>-->
? ? ? ? ? ? <!--?? ??? ??? ??? ??? ?<artifactId>logback-classic</artifactId>-->
? ? ? ? ? ? <!--?? ??? ??? ??? ?</exclusion>-->

? ? ? ? ? ? <!--?? ??? ??? ?</exclusions>-->
? ? ? ? ? ? <exclusions>
? ? ? ? ? ? ? ? <exclusion>
? ? ? ? ? ? ? ? ? ? <groupId>org.springframework.boot</groupId>
? ? ? ? ? ? ? ? ? ? <artifactId>spring-boot-starter-logging</artifactId>
? ? ? ? ? ? ? ? </exclusion>
? ? ? ? ? ? </exclusions>
? ? ? ? </dependency>
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>org.springframework.boot</groupId>
? ? ? ? ? ? <artifactId>spring-boot-starter-test</artifactId>
? ? ? ? ? ? <!-- <scope>test</scope> -->
? ? ? ? </dependency>
? ? ? ? <!--日志框架-->
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>org.apache.logging.log4j</groupId>
? ? ? ? ? ? <artifactId>log4j-api</artifactId>
? ? ? ? ? ? <version>${log4j.version}</version>
? ? ? ? </dependency>
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>org.apache.logging.log4j</groupId>
? ? ? ? ? ? <artifactId>log4j-core</artifactId>
? ? ? ? ? ? <version>${log4j.version}</version>
? ? ? ? </dependency>
? ? ? ? <!--日志框架-->
? ? </dependencies>

? ? <build>
? ? ? ? <plugins>
? ? ? ? ? ? <plugin>
? ? ? ? ? ? ? ? <groupId>org.apache.maven.plugins</groupId>
? ? ? ? ? ? ? ? <artifactId>maven-compiler-plugin</artifactId>
? ? ? ? ? ? ? ? <version>3.7.0</version>
? ? ? ? ? ? ? ? <configuration>
? ? ? ? ? ? ? ? ? ? <source>1.8</source>
? ? ? ? ? ? ? ? ? ? <target>1.8</target>
? ? ? ? ? ? ? ? ? ? <encoding>UTF-8</encoding>
? ? ? ? ? ? ? ? </configuration>
? ? ? ? ? ? </plugin>
? ? ? ? ? ? <plugin>

? ? ? ? ? ? ? ? <groupId>org.apache.maven.plugins</groupId>

? ? ? ? ? ? ? ? <artifactId>maven-assembly-plugin</artifactId>

? ? ? ? ? ? ? ? <version>2.5.5</version>

? ? ? ? ? ? ? ? <configuration>
? ? ? ? ? ? ? ? ? ? <archive>
? ? ? ? ? ? ? ? ? ? ? ? <manifest>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <mainClass>com.example.demo1.Demo1Application</mainClass>
? ? ? ? ? ? ? ? ? ? ? ? </manifest>
? ? ? ? ? ? ? ? ? ? </archive>
? ? ? ? ? ? ? ? ? ? <descriptorRefs>
? ? ? ? ? ? ? ? ? ? ? ? <descriptorRef>jar-with-dependencies</descriptorRef>
? ? ? ? ? ? ? ? ? ? </descriptorRefs>
? ? ? ? ? ? ? ? </configuration>
? ? ? ? ? ? ? ? <executions>
? ? ? ? ? ? ? ? ? ? <execution>
? ? ? ? ? ? ? ? ? ? ? ? <id>make-assembly</id>
? ? ? ? ? ? ? ? ? ? ? ? <phase>package</phase>
? ? ? ? ? ? ? ? ? ? ? ? <goals>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <goal>single</goal>
? ? ? ? ? ? ? ? ? ? ? ? </goals>
? ? ? ? ? ? ? ? ? ? </execution>
? ? ? ? ? ? ? ? </executions>
? ? ? ? ? ? </plugin>
? ? ? ? </plugins>
? ? </build>
</project>

5、先在本地測(cè)試,啟動(dòng)項(xiàng)目,看到這個(gè)就說(shuō)明啟動(dòng)成功了

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/

6、測(cè)試,在瀏覽器中依次輸入

http://127.0.0.1:3001/v1
http://127.0.0.1:3001/v1/test1
http://127.0.0.1:3001/v1/test2

在瀏覽器中能看到端口號(hào)的打印信息就說(shuō)明成功了

7、maven編譯打成jar包

8、修改nginx.conf文件

worker_processes ?1;

events {
? ? worker_connections ?1024;
}


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

? ? sendfile ? ? ? ?on;
? ??
? ? keepalive_timeout ?65;

? ? server {
? ? ? ? listen ? ? ? 89;
? ? ? ? server_name ?nginx_server;

? ? ? ? location / {
? ? ? ? ? ? proxy_pass http://server_ip:3001/v1;
? ? ? ? }
?? ??? ?location /edu {
? ? ? ? ? ? proxy_pass http://server_ip:3001/v1/test1;
? ? ? ? }
?? ??? ?location /ymd {
? ? ? ? ? ? proxy_pass http://server_ip:3002/v1/test2;
? ? ? ? }
? ? }

}

nginx_server:nginx所在的服務(wù)器的地址

server_ip:反向代理的服務(wù)器的地址

這里我都是10.161.20.10

7、測(cè)試,根據(jù)訪問(wèn)的路徑跳轉(zhuǎn)到不同的服務(wù)中

瀏覽器中輸入:

http://10.161.20.10:90/

invoke url /,port=3001

http://10.161.20.10:90/test1

invoke url /test1,port=3001

http://10.161.20.10:90/test2

invoke url /test2,port=3002

到此這篇關(guān)于Nginx部署SpringBoot項(xiàng)目的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)Nginx部署SpringBoot內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大阿家以后多多支持腳本之家!

相關(guān)文章

  • 阿里云部署Ubuntu 1.4 Flask + WSGI + Nginx 詳解

    阿里云部署Ubuntu 1.4 Flask + WSGI + Nginx 詳解

    本文解決的是 Flask 最后一公里的問(wèn)題:Linux 部署,需要的朋友可以參考下
    2017-12-12
  • Nginx部署項(xiàng)目上傳文件報(bào)錯(cuò)413的解決方法

    Nginx部署項(xiàng)目上傳文件報(bào)錯(cuò)413的解決方法

    本文主要介紹了Nginx部署項(xiàng)目上傳文件報(bào)錯(cuò)413的解決方法,報(bào)錯(cuò)413是因?yàn)镹ginx對(duì)上傳大小做了限制,所以我們需要配置文件,下面就來(lái)解決這個(gè)問(wèn)題,感興趣的可以了解一下
    2024-03-03
  • Nginx負(fù)載均衡以及動(dòng)靜分離的原理與配置

    Nginx負(fù)載均衡以及動(dòng)靜分離的原理與配置

    動(dòng)靜分離和負(fù)載均衡都是配置nginx實(shí)現(xiàn)對(duì)請(qǐng)求進(jìn)行操作,所以下面這篇文章主要給大家介紹了關(guān)于Nginx負(fù)載均衡以及動(dòng)靜分離的相關(guān)資料,需要的朋友可以參考下
    2021-06-06
  • Nginx查看當(dāng)前連接數(shù)的配置方法

    Nginx查看當(dāng)前連接數(shù)的配置方法

    在開(kāi)發(fā)過(guò)程中有時(shí)候我們需要查看Nginx的當(dāng)前連接數(shù),方便調(diào)整一些參數(shù)配置和性能調(diào)優(yōu),在Nginx中,你可以通過(guò)幾種方式來(lái)查看當(dāng)前的連接數(shù),感興趣的朋友一起看看吧
    2024-08-08
  • Nginx結(jié)合Openresty通過(guò)Lua+Redis實(shí)現(xiàn)動(dòng)態(tài)封禁IP

    Nginx結(jié)合Openresty通過(guò)Lua+Redis實(shí)現(xiàn)動(dòng)態(tài)封禁IP

    為了封禁某些爬蟲(chóng)或者惡意用戶對(duì)服務(wù)器的請(qǐng)求,我們需要建立一個(gè)動(dòng)態(tài)的 IP 黑名單,本文主要介紹了Nginx結(jié)合Openresty通過(guò)Lua+Redis實(shí)現(xiàn)動(dòng)態(tài)封禁IP,感興趣的可以了解一下
    2023-11-11
  • centos7編譯安裝nginx的方法步驟

    centos7編譯安裝nginx的方法步驟

    這篇文章主要介紹了centos7編譯安裝nginx的方法步驟,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-07-07
  • Nginx配置本地圖片服務(wù)器的實(shí)現(xiàn)

    Nginx配置本地圖片服務(wù)器的實(shí)現(xiàn)

    本文主要介紹了Nginx配置本地圖片服務(wù)器的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-12-12
  • Nginx訪問(wèn)慢問(wèn)題解決辦法(慢1s)

    Nginx訪問(wèn)慢問(wèn)題解決辦法(慢1s)

    這篇文章主要給大家介紹了關(guān)于Nginx訪問(wèn)慢問(wèn)題解決辦法的相關(guān)資料,訪問(wèn)速度對(duì)網(wǎng)站是極為關(guān)鍵的因素,而服務(wù)器對(duì)其影響最為深遠(yuǎn),需要的朋友可以參考下
    2023-08-08
  • Nginx中代理的上下文路徑設(shè)置方式

    Nginx中代理的上下文路徑設(shè)置方式

    這篇文章主要介紹了Nginx中代理的上下文路徑設(shè)置方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2025-03-03
  • Nginx實(shí)現(xiàn)負(fù)載均衡的方法總結(jié)

    Nginx實(shí)現(xiàn)負(fù)載均衡的方法總結(jié)

    這篇文章主要給大家總結(jié)介紹了關(guān)于Nginx實(shí)現(xiàn)負(fù)載均衡的一些方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Nginx具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-09-09

最新評(píng)論

杭锦旗| 南乐县| 翼城县| 三亚市| 长兴县| 虎林市| 靖江市| 林州市| 彝良县| 普洱| 巨鹿县| 新巴尔虎右旗| 昭通市| 永平县| 巴青县| 申扎县| 保靖县| 青州市| 崇义县| 抚顺县| 舒兰市| 奈曼旗| 平凉市| 兴安县| 万盛区| 东阳市| 定结县| 赤壁市| 紫金县| 永定县| 深州市| 青海省| 信丰县| 高雄县| 沂源县| 闸北区| 麻栗坡县| 寿光市| 乌鲁木齐市| 塔城市| 新安县|