nginx unit java 试用

unit 当前已经支持java了,当时支持基于servlet 的开发模式,以下是一个简单的学习
基于官方的demo

环境准备

  • docker-compose文件
 
version: "3"
services:
  app:
   build: ./
   ports:
   - "8080:8080"
   - "9000:9000" 
  • dockerfile
# keep our base image as small as possible
FROM nginx/unit:1.11.0-minimal
# port used by the listener in config.json
EXPOSE 8080
# add Java language and corresponding language module
RUN apt update \
    && apt install -y apt-transport-https gnupg1 \
    && curl https://nginx.org/keys/nginx_signing.key | apt-key add - \
    && echo "deb https://packages.nginx.org/unit/debian/ stretch unit" \
         > /etc/apt/sources.list.d/unit.list \
    && echo "deb-src https://packages.nginx.org/unit/debian/ stretch unit" \
         >> /etc/apt/sources.list.d/unit.list \
    && apt update \
    && mkdir -p /usr/share/man/man1/ \
    && apt install -y openjdk-8-jdk unit-jsc8 \
# final cleanup
    && apt remove -y apt-transport-https gnupg1 \
    && apt autoremove --purge -y \
    && rm -rf /var/lib/apt/lists/* /etc/apt/sources.list.d/*.list
# application setup
RUN mkdir /www/ && echo \
    '<%@page language="java" contentType="text/plain"%><%="Hello, Unit!"%>'\
    > /www/index.jsp \
# launch Unit
    && unitd --control unix:/var/run/control.unit.sock \
# upload the app config to Unit
    && curl -X PUT --data-binary '{ \
    "listeners": { \
        "*:8080": { \
            "pass": "applications/java_app" \
        } \
    }, \
    "applications": { \
        "java_app": { \
            "type": "java", \
            "webapp": "/www/" \
        } \
    } \
    }' --unix-socket /var/run/control.unit.sock http://localhost/config/

配置说明

对于java 项目的支持配置如下:

{
    "type": "java",
    "classpath": ["/www/qwk2mart/lib/qwk2mart-2.0.0.jar"],
    "options": ["-Dlog_path=/var/log/qwk2mart.log"],
    "webapp": "/www/qwk2mart/qwk2mart.war"
}

type 指定为java 语言,classpath 为依赖的jar 包 ,options指定jvm启动的一些参数,比如上边的日志,webapp,指定应用程序的路径
或者未解压包(war)的文件

启动&&测试

  • 启动
docker-compose build && docker-compose up -d
  • 效果

 

 

说明

关于集成java 的原理还需要看看源码,从原理上还是cgi编程,同时使用doker 运行有点太大了

参考资料

https://unit.nginx.org/configuration/#java

posted on   荣锋亮  阅读(680)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2018-09-27 stenciljs 学习十三 @stencil/router 组件使用说明
2018-09-27 stenciljs 学习十二 官方doc 路由使用的例子
2018-09-27 stenciljs 学习十一 pwa 支持
2018-09-27 stenciljs 学习十 服务器端渲染
2018-09-27 stenciljs 学习九 使用jsx
2018-09-27 stenciljs 学习八 组件测试
2018-09-27 stenciljs 学习七 路由

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示