From 4a159b9b356db07f3691deb63eab2c85838d893b Mon Sep 17 00:00:00 2001 From: rsonghuster Date: Thu, 14 Jul 2022 10:26:21 +0800 Subject: [PATCH] add nginx --- readme.md | 3 + readme_en.md | 3 + update.list | 2 +- web-framework/nginx/hook/index.js | 26 +++++ web-framework/nginx/publish.yaml | 58 +++++++++++ web-framework/nginx/readme.md | 1 + web-framework/nginx/src/code/nginx.conf | 126 ++++++++++++++++++++++++ web-framework/nginx/src/readme.md | 89 +++++++++++++++++ web-framework/nginx/src/s.yaml | 95 ++++++++++++++++++ web-framework/nginx/src/s_en.yaml | 97 ++++++++++++++++++ web-framework/nginx/version.md | 2 + 11 files changed, 501 insertions(+), 1 deletion(-) create mode 100644 web-framework/nginx/hook/index.js create mode 100755 web-framework/nginx/publish.yaml create mode 120000 web-framework/nginx/readme.md create mode 100644 web-framework/nginx/src/code/nginx.conf create mode 100644 web-framework/nginx/src/readme.md create mode 100644 web-framework/nginx/src/s.yaml create mode 100644 web-framework/nginx/src/s_en.yaml create mode 100644 web-framework/nginx/version.md diff --git a/readme.md b/readme.md index 96cbfb911..7541b9551 100644 --- a/readme.md +++ b/readme.md @@ -91,6 +91,9 @@ > SSR 框架: > - [nuxt-ssr](./web-framework/nodejs/custom-runtime/nuxt-ssr/src): `s init start-nuxt-ssr` +> Nginx 框架: +> - [nginx](./web-framework/nginx/src): `s init start-nginx` + > 为了对比Custom运行时和编程语言原生运行时的框架迁移区别,可以参考以下案例进行自行对比: > > | 框架名 | Custom运行时 | Node.js 12运行时 | diff --git a/readme_en.md b/readme_en.md index 2ce4557e5..bd9ab31e5 100644 --- a/readme_en.md +++ b/readme_en.md @@ -92,6 +92,9 @@ At present, this case repository contains the deployment cases of the following > SSR frameworks > - [nuxt-ssr](./web-framework/nodejs/custom-runtime/nuxt-ssr/src): `s init start-nuxt-ssr` +> Nginx: +> - [nginx](./web-framework/nginx/src): `s init start-nginx` + > In order to compare the framework migration differences between the Custom runtime and the programming language native runtime, you can refer to the following cases for your own comparison: > > | Framework name | Custom runtime | Node.js 12 runtime | diff --git a/update.list b/update.list index c64643ab4..1f36b72fd 100755 --- a/update.list +++ b/update.list @@ -1 +1 @@ -web-framework/nodejs/custom-runtime/nest \ No newline at end of file +web-framework/nginx \ No newline at end of file diff --git a/web-framework/nginx/hook/index.js b/web-framework/nginx/hook/index.js new file mode 100644 index 000000000..42599e7e3 --- /dev/null +++ b/web-framework/nginx/hook/index.js @@ -0,0 +1,26 @@ +async function preInit(inputObj) { + console.log(` + Serverless Devs Application Case + + Cloud services required: + - FC : https://fc.console.aliyun.com/ + + Tips: + - Serverless Devs Version >= v2.0.103 + - FC Component: https://www.serverless-devs.com/fc/readme + `) +} + +async function postInit(inputObj) { + console.log(` + * Before using, please check whether the actions command in Yaml file is available + * Carefully reading the notes in s.yaml is helpful for the use of the tool + * FC is only used as the execution environment, and the business code is in NAS + * If need help in the use process, please apply to join the Dingtalk Group: 33947367 + `) +} + +module.exports = { + postInit, + preInit +} \ No newline at end of file diff --git a/web-framework/nginx/publish.yaml b/web-framework/nginx/publish.yaml new file mode 100755 index 000000000..4bae698e2 --- /dev/null +++ b/web-framework/nginx/publish.yaml @@ -0,0 +1,58 @@ +Type: Application +Name: start-nginx +Provider: + - 阿里云 +Version: 0.0.1 +Description: 快速部署 nginx 到函数计算 +HomePage: https://github.com/devsapp/start-web-framework +Tags: + - Web框架 + - nginx +Category: Web框架 +Service: + 函数计算: + Authorities: + - AliyunFCFullAccess +Parameters: + type: object + additionalProperties: false # 不允许增加其他属性 + required: # 必填项 + - region + - serviceName + - functionName + properties: + region: + title: 地域 + type: string + default: cn-hangzhou + description: 创建应用所在的地区 + enum: + - cn-beijing + - cn-hangzhou + - cn-shanghai + - cn-qingdao + - cn-zhangjiakou + - cn-huhehaote + - cn-shenzhen + - cn-chengdu + - cn-hongkong + - ap-southeast-1 + - ap-southeast-2 + - ap-southeast-3 + - ap-southeast-5 + - ap-northeast-1 + - eu-central-1 + - eu-west-1 + - us-west-1 + - us-east-1 + - ap-south-1 + serviceName: + title: 服务名 + type: string + default: web-framework + description: 服务名称,只能包含字母、数字、下划线和中划线。不能以数字、中划线开头。长度在 1-128 之间 + functionName: + title: 函数名 + type: string + default: nginx + description: 函数名称,只能包含字母、数字、下划线和中划线。不能以数字、中划线开头。长度在 1-64 之间 diff --git a/web-framework/nginx/readme.md b/web-framework/nginx/readme.md new file mode 120000 index 000000000..80cd4735d --- /dev/null +++ b/web-framework/nginx/readme.md @@ -0,0 +1 @@ +./src/readme.md \ No newline at end of file diff --git a/web-framework/nginx/src/code/nginx.conf b/web-framework/nginx/src/code/nginx.conf new file mode 100644 index 000000000..1c0263c33 --- /dev/null +++ b/web-framework/nginx/src/code/nginx.conf @@ -0,0 +1,126 @@ + +#user nobody; +#Defines which Linux system user will own and run the Nginx server + +worker_processes auto; +#Referes to single threaded process. Generally set to be equal to the number of CPUs or cores. + +#error_log logs/error.log; #error_log logs/error.log notice; +#Specifies the file where server logs. + +#pid logs/nginx.pid; +#nginx will write its master process ID(PID). + +events { + worker_connections 1024; + # worker_processes and worker_connections allows you to calculate maxclients value: + # max_clients = worker_processes * worker_connections +} + + +http { + # anything written in /opt/nginx/conf/mime.types is interpreted as if written inside the http { } block + # + + #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + # '$status $body_bytes_sent "$http_referer" ' + # '"$http_user_agent" "$http_x_forwarded_for"'; + + #access_log logs/access.log main; + # If serving locally stored static files, sendfile is essential to speed up the server, + # But if using as reverse proxy one can deactivate it + + #tcp_nopush on; + # works opposite to tcp_nodelay. Instead of optimizing delays, it optimizes the amount of data sent at once. + + #keepalive_timeout 0; + keepalive_timeout 900; + # timeout during which a keep-alive client connection will stay open. + + #gzip on; + # tells the server to use on-the-fly gzip compression. + + server { + # You would want to make a separate file with its own server block for each virtual domain + # on your server and then include them. + listen 9000; + #tells Nginx the hostname and the TCP port where it should listen for HTTP connections. + # listen 9000; is equivalent to listen *:9000; + + server_name localhost; + # lets you doname-based virtual hosting + + #charset koi8-r; + + #access_log logs/host.access.log main; + + #error_page 404 /404.html; + + # redirect server error pages to the static page /50x.html + # + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root html; + } + + # proxy the PHP scripts to Apache listening on 127.0.0.1:80 + # + #location ~ \.php$ { + # proxy_pass http://127.0.0.1; + #} + + # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 + # + #location ~ \.php$ { + # root html; + # fastcgi_pass 127.0.0.1:9000; + # fastcgi_index index.php; + # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; + # include fastcgi_params; + #} + + # deny access to .htaccess files, if Apache's document root + # concurs with nginx's one + # + #location ~ /\.ht { + # deny all; + #} + } + + + # another virtual host using mix of IP-, name-, and port-based configuration + # + #server { + # listen 8000; + # listen somename:8080; + # server_name somename alias another.alias; + + # location / { + # root html; + # index index.html index.htm; + # } + #} + + + # HTTPS server + # + #server { + # listen 443 ssl; + # server_name localhost; + + # ssl_certificate cert.pem; + # ssl_certificate_key cert.key; + + # ssl_session_cache shared:SSL:1m; + # ssl_session_timeout 5m; + + # ssl_ciphers HIGH:!aNULL:!MD5; + # ssl_prefer_server_ciphers on; + + # location / { + # root html; + # index index.html index.htm; + # } + #} + +} \ No newline at end of file diff --git a/web-framework/nginx/src/readme.md b/web-framework/nginx/src/readme.md new file mode 100644 index 000000000..6ee630fb8 --- /dev/null +++ b/web-framework/nginx/src/readme.md @@ -0,0 +1,89 @@ +# start-nginx 帮助文档 + +

+ + + + + + + + + +

+ + + +Z-Blog是由Z-Blog开发团队开发的一款小巧而强大的基于Asp和PHP平台的开源程序,致力于给用户提供优秀的博客写作体验 + + + + + +## 前期准备 +使用该项目,推荐您拥有以下的产品权限 / 策略: + +| 服务/业务 | 函数计算 | 硬盘挂载 | VPC | 其它 | +| --- | --- | --- | --- | --- | +| 权限/策略 | AliyunFCFullAccess | AliyunNASFullAccess | AliyunVPCFullAccess | AliyunECSFullAccess | + +
+ + + +# 代码 & 预览 + +- [ :smiley_cat: 源代码](https://github.com/devsapp/start-web-framework/blob/master/web-framework/nginx) + + + + + +## 部署 & 体验 + + + +- :fire: 通过 [Serverless 应用中心](https://fcnext.console.aliyun.com/applications/create?template=start-nginx) , +[![Deploy with Severless Devs](https://img.alicdn.com/imgextra/i1/O1CN01w5RFbX1v45s8TIXPz_!!6000000006118-55-tps-95-28.svg)](https://fcnext.console.aliyun.com/applications/create?template=start-nginx) 该应用。 + + + +- 通过 [Serverless Devs Cli](https://www.serverless-devs.com/serverless-devs/install) 进行部署: + - [安装 Serverless Devs Cli 开发者工具](https://www.serverless-devs.com/serverless-devs/install) ,并进行[授权信息配置](https://www.serverless-devs.com/fc/config) ; + - 初始化项目:`s init start-nginx -d start-nginx` + - 进入项目,并进行项目部署:`cd start-nginx && s deploy -y` + + + + + +# 应用详情 + + +本项目是将 nginx 部署到阿里云 Serverless 平台(函数计算 FC)。 + +通过 Serverless Devs 开发者工具,您只需要几步,就可以体验 Serverless 架构,带来的降本提效的技术红利。 + +部署完成之后,您可以看到系统返回给您的案例地址, 此时,打开案例地址,就可以进入 nginx 默认的首页: + +![图片alt](https://img.alicdn.com/imgextra/i3/O1CN01C1yDPT1oBhA7JjW4y_!!6000000005187-2-tps-2090-666.png) + + + + + + + +## 开发者社区 + +您如果有关于错误的反馈或者未来的期待,您可以在 [Serverless Devs repo Issues](https://github.com/serverless-devs/serverless-devs/issues) 中进行反馈和交流。如果您想要加入我们的讨论组或者了解 FC 组件的最新动态,您可以通过以下渠道进行: + +

+ +| | | | +|--- | --- | --- | +|

微信公众号:`serverless`
|
微信小助手:`xiaojiangwh`
|
钉钉交流群:`33947367`
| + +

+ +
\ No newline at end of file diff --git a/web-framework/nginx/src/s.yaml b/web-framework/nginx/src/s.yaml new file mode 100644 index 000000000..1e82001d8 --- /dev/null +++ b/web-framework/nginx/src/s.yaml @@ -0,0 +1,95 @@ +# ------------------------------------ +# If you need English case, you can refer to [s_en.yaml] file +# ------------------------------------ +# 欢迎您使用阿里云函数计算 FC 组件进行项目开发 +# 组件仓库地址:https://github.com/devsapp/fc +# 组件帮助文档:https://www.serverless-devs.com/fc/readme +# Yaml参考文档:https://www.serverless-devs.com/fc/yaml/readme +# 关于: +# - Serverless Devs和FC组件的关系、如何声明/部署多个函数、超过50M的代码包如何部署 +# - 关于.fcignore使用方法、工具中.s目录是做什么、函数进行build操作之后如何处理build的产物 +# 等问题,可以参考文档:https://www.serverless-devs.com/fc/tips +# 关于如何做CICD等问题,可以参考:https://www.serverless-devs.com/serverless-devs/cicd +# 关于如何进行环境划分等问题,可以参考:https://www.serverless-devs.com/serverless-devs/extend +# 更多函数计算案例,可参考:https://github.com/devsapp/awesome/ +# 有问题快来钉钉群问一下吧:33947367 +# ------------------------------------ +edition: 1.0.0 +name: web-framework-app +# access 是当前应用所需要的密钥信息配置: +# 密钥配置可以参考:https://www.serverless-devs.com/serverless-devs/command/config +# 密钥使用顺序可以参考:https://www.serverless-devs.com/serverless-devs/tool#密钥使用顺序与规范 +access: "{{ access }}" + +vars: # 全局变量 + region: "{{ region }}" + service: + name: "{{ serviceName }}" + description: 'Serverless Devs Web Framework Service' + nasConfig: auto + +services: + framework: # 业务名称/模块名称 + # 如果只想针对 framework 下面的业务进行相关操作,可以在命令行中加上 framework,例如: + # 只对framework进行构建:s framework build + # 如果不带有 framework ,而是直接执行 s build,工具则会对当前Yaml下,所有和 framework 平级的业务模块(如有其他平级的模块,例如下面注释的next-function),按照一定顺序进行 build 操作 + component: fc # 组件名称,Serverless Devs 工具本身类似于一种游戏机,不具备具体的业务能力,组件类似于游戏卡,用户通过向游戏机中插入不同的游戏卡实现不同的功能,即通过使用不同的组件实现不同的具体业务能力 + actions: # 自定义执行逻辑,关于actions 的使用,可以参考:https://www.serverless-devs.com/serverless-devs/yaml#行为描述 +# pre-deploy: # 在deploy之前运行 +# - run: pip3 install -r requirements.txt -t . # 要执行的系统命令,类似于一种钩子的形式 +# path: ./code # 执行系统命令/钩子的路径 +# - component: fc build --use-docker # 要运行的组件,格式为【component: 组件名 命令 参数】(可以通过s cli registry search --type Component 获取组件列表) +# - plugin: myplugin # 与运行的插件 (可以通过s cli registry search --type Plugin 获取组件列表) +# args: # 插件的参数信息 +# testKey: testValue + props: # 组件的属性值 + region: ${vars.region} # 关于变量的使用方法,可以参考:https://www.serverless-devs.com/serverless-devs/yaml#变量赋值 + service: ${vars.service} + function: + name: "{{ functionName }}" + description: 'Serverless Devs Web Framework Function' + codeUri: './code' + runtime: custom + timeout: 300 + memorySize: 1536 + caPort: 9000 + instanceConcurrency: 8 + customRuntimeConfig: + command: + - nginx + args: + - '-c' + - '/code/nginx.conf' + - '-g' + - 'daemon off;' + triggers: + - name: httpTrigger + type: http + config: + authType: anonymous + methods: + - GET + - POST + - PUT + - DELETE + - HEAD + - OPTIONS + customDomains: + - domainName: auto + protocol: HTTP + routeConfigs: + - path: /* +# next-function: # 第二个函数的案例,仅供参考 +# # 如果在当前项目下执行 s deploy,会同时部署模块: +# # helloworld:服务hello-world-service,函数cpp-event-function +# # next-function:服务hello-world-service,函数next-function-example +# # 如果想单独部署当前服务与函数,可以执行 s + 模块名/业务名 + deploy,例如:s next-function deploy +# # 如果想单独部署当前函数,可以执行 s + 模块名/业务名 + deploy function,例如:s next-function deploy function +# # 更多命令可参考:https://www.serverless-devs.com/fc/readme#文档相关 +# component: fc +# props: +# region: ${vars.region} +# service: ${vars.service} # 应用整体的服务配置 +# function: # 定义一个新的函数 +# name: next-function-example +# description: 'hello world by serverless devs' \ No newline at end of file diff --git a/web-framework/nginx/src/s_en.yaml b/web-framework/nginx/src/s_en.yaml new file mode 100644 index 000000000..356b854ce --- /dev/null +++ b/web-framework/nginx/src/s_en.yaml @@ -0,0 +1,97 @@ +# ------------------------------------ +# If you want to use this file directly, please add [-t/--template] parameter, for example [s deploy -t s_en.yaml] +# ------------------------------------ +# Welcome to use Alibaba Cloud Function Compute FC components for project development +# Component warehouse address: https://github.com/devsapp/fc +# Component help documentation: https://www.serverless-devs.com/fc/readme +# Yaml reference documentation: https://www.serverless-devs.com/fc/yaml/readme +# About: +# - The relationship between Serverless Devs and FC components, how to declare/deploy multiple functions, how to deploy code packages over 50M +# - About the usage of .fcignore, what the .s directory in the tool does, and how to process the build product after the function performs the build operation +# and other issues, you can refer to the documentation: https://www.serverless-devs.com/fc/tips +# For questions about how to do CICD, please refer to: https://www.serverless-devs.com/serverless-devs/cicd +# For issues such as how to divide the environment, please refer to: https://www.serverless-devs.com/serverless-devs/extend +# For more function calculation cases, please refer to: https://github.com/devsapp/awesome/blob/main/README_en.md +# If you have any questions, please come to the DingTalk group and ask: 33947367 +# ------------------------------------ +edition: 1.0.0 +name: web-framework-app +# access is the key information configuration required by the current application: +# Key configuration can refer to: https://www.serverless-devs.com/serverless-devs/command/config +# For the order of key usage, please refer to: https://www.serverless-devs.com/serverless-devs/tool#Key usage order and specification +# access: default + +vars: # global variables + region: cn-hangzhou + service: + name: hello-world-service + description: 'Serverless Devs Web Framework Service' + nasConfig: auto + +services: + framework: # business name/module name + # If you only want to perform related operations on the business below framework, you can add framework to the command line, for example: + # Build only framework: s framework build + # If s build is directly executed without framework, the tool will perform the same operation on all business modules at the same level as framework under the current Yaml (if there are other level modules, such as the next-function commented below), according to certain Sequential build operations + component: fc # The name of the component. The Serverless Devs tool itself is similar to a game console and does not have specific business capabilities. The component is similar to a game card. Users can achieve different functions by inserting different game cards into the game console, that is, by using Different components implement different specific business capabilities + actions: # Customize execution logic. For the use of actions, please refer to: https://www.serverless-devs.com/serverless-devs/yaml#Behavior description + # pre-deploy: # run before deploy + # - run: pip3 install -r requirements.txt -t . + # path: ./code + # - component: fc build --use-docker # The component to run, the format is [component: component name command parameter] (you can get the component list through s cli registry search --type Component) + # - run: docker build xxx # System command to execute, similar to a hook + # path: ./src # The path to execute system commands/hooks + # - plugin: myplugin # and running plugins (you can get a list of components via s cli registry search --type Plugin) + # args: # parameter information of the plugin + # testKey: testValue + props: + region: ${vars.region} # For the usage of variables, please refer to: https://www.serverless-devs.com/serverless-devs/yaml#Variable assignment + service: ${vars.service} + function: + name: nginx + description: 'Serverless Devs Web Framework Function' + codeUri: './code' + runtime: custom + timeout: 300 + memorySize: 1536 + caPort: 9000 + instanceConcurrency: 8 + customRuntimeConfig: + command: + - nginx + args: + - '-c' + - '/code/nginx.conf' + - '-g' + - 'daemon off;' + triggers: + - name: httpTrigger + type: http + config: + authType: anonymous + methods: + - GET + - POST + - PUT + - DELETE + - HEAD + - OPTIONS + customDomains: + - domainName: auto + protocol: HTTP + routeConfigs: + - path: /* +# next-function: # The case of the second function, just for reference +# # If you execute s deploy under the current project, the modules will be deployed at the same time: +# # helloworld: service hello-world-service, function cpp-event-function +# # next-function: service hello-world-service, function next-function-example +# # If you want to deploy the current service and function separately, you can execute s + module name/business name + deploy, for example: s next-function deploy +# # If you want to deploy the current function separately, you can execute s + module name/business name + deploy function, for example: s next-function deploy function +# # For more commands, please refer to: https://www.serverless-devs.com/fc/readme#Document related +# component: fc +# props: +# region: ${vars.region} +# service: ${vars.service} # The overall service configuration of the application +# function: # define a new function +# name: next-function-example +# description: 'hello world by serverless devs' \ No newline at end of file diff --git a/web-framework/nginx/version.md b/web-framework/nginx/version.md new file mode 100644 index 000000000..92aaf1563 --- /dev/null +++ b/web-framework/nginx/version.md @@ -0,0 +1,2 @@ +- 更新帮助文档 +- 发布全新Web-framework解决方案 \ No newline at end of file