广告
返回顶部
首页 > 资讯 > 精选 >Nginx如何部署SpringBoot项目
  • 280
分享到

Nginx如何部署SpringBoot项目

2023-07-05 08:07:06 280人浏览 薄情痞子
摘要

本篇内容介绍了“Nginx如何部署SpringBoot项目”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!新建一个yml文件 applicat

本篇内容介绍了“Nginx如何部署SpringBoot项目”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

新建一个yml文件 application.yml

# 端口号server:  port: 2001

编写一个Controler测试

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;    }}

编写一个启动类

package com.example.demo1;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplicationpublic class Demo1Application {    public static void main(String[] args) {        SpringApplication.run(Demo1Application.class, args);    }}

我用到的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>

先在本地测试,启动项目,看到这个就说明启动成功了

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

测试,在浏览器中依次输入

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

在浏览器中能看到端口号的打印信息就说明成功了

maven编译打成jar包

修改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所在的服务器的地址

server_ip:反向代理的服务器的地址

这里我都是10.161.20.10

测试,根据访问的路径跳转到不同的服务中

浏览器中输入:

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

“Nginx如何部署SpringBoot项目”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注编程网网站,小编将为大家输出更多高质量的实用文章!

--结束END--

本文标题: Nginx如何部署SpringBoot项目

本文链接: https://www.lsjlt.com/news/350707.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Nginx如何部署SpringBoot项目
    本篇内容介绍了“Nginx如何部署SpringBoot项目”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!新建一个yml文件 applicat...
    99+
    2023-07-05
  • Nginx部署SpringBoot项目的实现
    笔记记录一下用Nginx部署SpringBoot项目 1、新建一个yml文件 application.yml # 端口号 server: port: 2001 2、编写一个Co...
    99+
    2023-03-06
    Nginx部署SpringBoot
  • nginx如何部署php7项目
    这篇文章主要讲解了“nginx如何部署php7项目”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“nginx如何部署php7项目”吧!nginx部署php7项目的方法:1、通过install安...
    99+
    2023-06-22
  • uwsgi+nginx项目部署
    部署Django项目 Django+uWSGI+nginx 部署 django 一个pyhton的开源web框架。 uWSGI 一个基于自有的uwsgi协议、WSGI协议和http服务协议的web网关 nginx 常用的代理服务器 ...
    99+
    2023-01-31
    项目 uwsgi nginx
  • Dockerfile部署SpringBoot项目
    Dockerfile部署SpringBoot项目 文章目录 利用Dockerfile部署SpringBoot项目 1、创建一个SpringBooot项目并且打成jar包2、在Linux中...
    99+
    2023-09-29
    spring boot java docker
  • docker nginx如何部署多个项目
    今天小编给大家分享一下docker nginx如何部署多个项目的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们...
    99+
    2022-10-19
  • Linux下如何部署springboot项目
    本文小编为大家详细介绍“Linux下如何部署springboot项目”,内容详细,步骤清晰,细节处理妥当,希望这篇“Linux下如何部署springboot项目”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。在po...
    99+
    2023-07-06
  • 如何使用dockerfile部署springboot项目
    这篇文章主要讲解了“如何使用dockerfile部署springboot项目”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“如何使用dockerfile部署springboot项目”吧!一、d...
    99+
    2023-07-06
  • Jenkins如何自动部署SpringBoot项目
    这篇文章给大家分享的是有关Jenkins如何自动部署SpringBoot项目的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。1、Jenkins安装下载jenkins安装包,maven安装包;打开xftp将安装包上传...
    99+
    2023-06-25
  • 【Docker】docker部署springboot+vue+mysql+nginx前后端分离项目【部署实战篇】
    文章目录 0、安装docker并准备一个springboot-vue前后端分离项目前后端打包放到服务器上1、docker 安装jdk2、docker 安装mysql通过Docker命令进入My...
    99+
    2023-09-03
    docker spring boot vue.js
  • nginx部署多个前端项目
    前提:nginx已在服务器上安装完成 假如有2个项目(一个company,一个test),需要通过ip或者域名来访问,我们通过http://www.test.com来举例 首先把2个静态资源项目或者打包好的项目放到Nginx中 1、ngin...
    99+
    2023-09-10
    nginx 运维 linux 服务器 前端
  • nginx下怎么部署php项目
    本文操作环境:linux5.9.8系统、nginx1.9版、Dell G3电脑。nginx下怎么部署php项目?nginx服务器上部署php项目 nginx本身不能处理PHP页面,它只是个web服务器,当接收到请求后,如果是P...
    99+
    2021-08-22
    nginx php
  • nginx下怎么部署vue项目
    本篇内容主要讲解“nginx下怎么部署vue项目”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“nginx下怎么部署vue项目”吧!首先要去nginx官网下下载n...
    99+
    2022-10-19
  • k8s集群部署springboot项目
    一、前言 本篇,我们将基于k8s集群,模拟一个比较接近实际业务的使用场景,使用k8s集群部署一个springboot的项目,我们的需求是: 部署SpringBoot项目到阿里云服务器 ; 基于容器打包,推送私有镜像仓库 ; 采用K8S集群...
    99+
    2023-09-06
    k8s集群部署java应用 k8s部署springboot k8s部署java应用 k8s部署微服务项目 k8s部署微服务
  • Springboot项目部署的方法
    今天小编给大家分享一下Springboot项目部署的方法的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。1 简介Springb...
    99+
    2023-06-08
  • centos+nginx+uwsgi部署django项目上线
    目录Python安装django相关库的安装nginx安装&配置(处理静态请求和代理动态请求到uwsgi)uwsgi安装&配置标题关闭setting.py的DEBUG...
    99+
    2022-11-11
  • 怎么使用Nginx部署Vue项目
    本篇内容主要讲解“怎么使用Nginx部署Vue项目”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“怎么使用Nginx部署Vue项目”吧!一、安装Nginx 使用XShell连接我们的服务器 配置 ...
    99+
    2023-06-30
  • Docker部署Springboot项目(含MySQL+Redis)
    使用Docker部署之前写的一个博客项目,主要用到了MySQL和Redis,Redis作网站访问量统计。下面会对具体的部署方式作详细讲解 一、服务器安装Docker 1、删除docker旧版本 sud...
    99+
    2023-09-15
    docker spring boot mysql redis java
  • 云服务器部署springboot项目
    要在云服务器上部署springboot项目,可以使用以下步骤: 创建一个新的云数据库:可以在云服务器上安装一个名为mybase.db的云数据库(可以使用默认的或自定义的数据库名称)。 在云服务器上创建一个springboot项目:使用 ...
    99+
    2023-10-26
    服务器 项目 springboot
  • idea中如何将springboot项目部署到docker
    这篇“idea中如何将springboot项目部署到docker”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“idea中如何...
    99+
    2023-06-08
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作