Home >
Article > Java > How Nginx deploys SpringBoot project
How Nginx deploys SpringBoot project
WBOYforward
2023-05-11 15:58:111672browse
1. Create a new yml file application.yml
# 端口号
server:
port: 2001
2. Write a Controller test class
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. Write a startup class
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. I use pom file
4.0.0org.springframework.bootspring-boot-starter-parent2.7.6com.exampledemo10.0.1-SNAPSHOTdemo1Demo project for Spring Boot1.82.19.0org.springframework.bootspring-boot-starterorg.springframework.bootspring-boot-starter-weborg.springframework.bootspring-boot-starter-loggingorg.springframework.bootspring-boot-starter-testorg.apache.logging.log4jlog4j-api${log4j.version}org.apache.logging.log4jlog4j-core${log4j.version}org.apache.maven.pluginsmaven-compiler-plugin3.7.01.81.8UTF-8org.apache.maven.pluginsmaven-assembly-plugin2.5.5com.example.demo1.Demo1Applicationjar-with-dependenciesmake-assemblypackagesingle
5. First test locally and start the project. Seeing this means the startup is successful
nginx_server: The address of the server where nginx is located
server_ip: The address of the reverse proxy server
Here I am They are all 10.161.20.10
7. Test and jump to different services according to the access path
Enter in the browser:
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
The above is the detailed content of How Nginx deploys SpringBoot project. For more information, please follow other related articles on the PHP Chinese website!
Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete