分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 运营维护

nginx unit ?docker 运行以及php &&golang 简单使用

发布时间:2023-09-06 01:53责任编辑:郭大石关键词:nginx
备注:
   nginx  unit  nginx 开源的新的nginx 开发平台,但是说白了,个人感觉一般,而且官方文档也不是很好,
api 接口目前暂时文档比较。。。。,以前写过虚拟机&&物理机安装部署的方式,今天写一个使用docker
进行安装部署的方式,同时添加golang语言的使用,算是比较全了,毕竟大部分公司再用容器。
 
1. 参考项目
https://github.com/rongfengliang/nginx-unit-docker-demo
2. 项目说明
a. 项目结构├── Dockerfile ??// docker 构建├── Jenkinsfile ?// jenkins 构建├── README.md├── app.go ??// golang 语言支持├── docker-compose.yml ?// docker-compose 构建├── run.sh ?// 应用配置,通过rest 接口├── start.json ?// 应用配置 ?php && golang └── website ???└── index.php ?// php 语言b. 代码说明(使用docker多阶段构建)Dockerfile docker 构建FROM golang:stretch AS build-envRUN apt-get update# RUN apt-get install -y build-essentialRUN git clone https://github.com/nginx/unit.git /go/src/github.com/nginx/unit## 注意分之的版本 必须和你的unit 一致,不然报错,这个觉得不好,可能和目前生产可用性有关系吧## 这个主要是golang sdk 的构建RUN cd /go/src/github.com/nginx/unit && git checkout tags/1.1 && ./configure && ./configure go && make go-installADD . /go/src/github.com/rongfengliang/nginx-unit-goRUN cd /go/src/github.com/rongfengliang/nginx-unit-go && go build -o /appdemo app.goFROM nginx/unit:1.1-fullWORKDIR /appdemoADD start.json ?/appdemo/start.json COPY website /appdemo/website/COPY --from=build-env /appdemo /appdemo/website/appdemoEXPOSE 8080 8000 8081CMD ["/usr/sbin/unitd", "--no-daemon","--control", "0.0.0.0:8000"]Jenkinsfile ?jenkinspipeline ?构建pipeline { ?agent { ???node { ?????label ‘docker-65‘ ???} ?} ?stages { ???stage(‘docker-compose build‘) { ?????steps { ???????sh ‘docker-compose build‘ ?????} ???} ???stage(‘docker-compose run ‘) { ?????steps { ???????sh ‘docker-compose up -d‘ ?????} ???} ???stage(‘deploy service‘) { ?????steps { ???????sh ‘./run.sh‘ ?????} ???} ?}}app.go ?golang 支持package mainimport ("math""net/http""nginx/unit" ## 注意unit 版本,感觉做的有点不好,因为版本因为无法发布服务)func term(ch chan float64, k float64) {ch <- 4 * math.Pow(-1, k) / (2*k + 1)}func handler(w http.ResponseWriter, r *http.Request) {w.Write([]byte("appdemorong"))}func main() {http.HandleFunc("/", handler)//http.ListenAndServe(":8080", nil)unit.ListenAndServe(":8089", nil)}docker-compose.yml ?比较简单,不用说了version: "3"services: ??nginx-unit: ???build: ?????context: . ???image: myunit ???ports: ?????- "9080:8080" ????- "9000:8000" ?????- "9001:8081"run.sh ??服务注册的shell#!/bin/shcurl -X PUT -d @$PWD/start.json http://localhost:9000start.json ?服务配置的说明{ ???"listeners":{ ???????"*:8080":{ ???????????"application":"phpindex" ???????}, ???????"*:8081":{ ???????????"application":"golang" ???????} ???}, ???"applications":{ ???????"phpindex":{ ??????????"type":"php", ??????????"processes":30, ??????????"root":"/appdemo/website", ??????????"index":"index.php" ???????}, ???????"golang":{ ???????????"type":"go", ???????????"processes":30, ???????????"working_directory": "/appdemo/website", ???????????"executable": "appdemo" ????????} ???}}website/index.php ?php ?语言支持<?php phpinfo()?>
3. 构建&&启动
docker-compose builddocker-compose up -d
4. 发布服务
./run.sh
5. 效果
 
a. 注册的服务列表
b. golang 服务访问
 
c.  php 服务访问
 
6. 扩展
多版本切换以及多版本也比较简单,就是服务注册配置文件的处理,总的来说,挺好的功能,但是在微服务,以及service mesh 的大趋势之下,就显得没有那么好的,
也只是个人的观点
7. 参考资料
http://unit.nginx.org/https://github.com/rongfengliang/nginx-unit-docker-demo

nginx unit ?docker 运行以及php &&golang 简单使用

原文地址:https://www.cnblogs.com/rongfengliang/p/9025222.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved