openresty 代理springboot应用,
openresty 代理springboot应用,
openresty 代理springboot应用
springboot 应用
HelloController
@RestController public class HelloController { @RequestMapping("/hello") public String hello(){ return "hello 瓜田李下"; } }
*************
docker 配置
Dockerfile
from java:8 workdir /usr/local/jar copy hello.jar app.jar expose 8080 entrypoint ["java", "-jar", "app.jar"]
edit configuartion ==> docker
启动应用,控制台输出
. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.7.1) 2022-07-01 03:16:17.667 INFO 1 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication v0.0.1-SNAPSHOT using Java 1.8.0_111 on a30602291ff8 with PID 1 (/usr/local/jar/app.jar started by root in /usr/local/jar) 2022-07-01 03:16:17.677 INFO 1 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to 1 default profile: "default" 2022-07-01 03:16:20.030 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http) 2022-07-01 03:16:20.059 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2022-07-01 03:16:20.060 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.64] 2022-07-01 03:16:20.263 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2022-07-01 03:16:20.264 INFO 1 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2446 ms 2022-07-01 03:16:21.307 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path '' 2022-07-01 03:16:21.328 INFO 1 --- [ main] com.example.demo.DemoApplication : Started DemoApplication in 4.715 seconds (JVM running for 5.828) 2022-07-01 03:16:32.720 INFO 1 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet' 2022-07-01 03:16:32.720 INFO 1 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet' 2022-07-01 03:16:32.722 INFO 1 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 2 ms
openresty 配置
default.conf
server { listen 80; server_name localhost; location / { proxy_pass http://172.18.0.3:8080; root /usr/share/nginx/html; index index.html index.htm; } }
创建容器
docker run -it -d --net fixed --ip 172.18.0.2 -p 9000:80 \ -v /Users/huli/lua/openresty/conf4/default.conf:/etc/nginx/conf.d/default.conf \ --name openresty4 lihu12344/openresty
使用测试
huli@bogon openresty % curl localhost:9000/hello hello 瓜田李下
评论暂时关闭