nginx.ts 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. import {FormColumnType} from "planning-tools";
  2. import {NgxModuleData} from "../pages/nginx/components/input.ts";
  3. export type INginx = {
  4. id: number
  5. name: string
  6. uid: string
  7. /**
  8. * 数据目录,所有自定义配置文件都在里面
  9. * conf.d stream.d backup certs
  10. */
  11. dataDir: string
  12. /**
  13. * nginx的配置文件主目录,及nginx.conf 配置文件所在的目录
  14. */
  15. nginxDir: string
  16. /**
  17. * nginx可执行文件
  18. */
  19. nginxPath?:string
  20. isLocal: boolean
  21. ipAddr: string
  22. port: number
  23. user: string
  24. password: string
  25. httpData: string
  26. httpConf: string
  27. remark: string
  28. /**
  29. * 版本信息
  30. */
  31. versionInfo?: string
  32. }
  33. /**
  34. * 虚拟主机或者 TCP/UDP代理
  35. */
  36. export type INginxServer = {
  37. /**
  38. * 唯一标识
  39. */
  40. id: number
  41. /**
  42. * 是否是负载均衡
  43. */
  44. isUpstream?: boolean
  45. /**
  46. * 是否为TCP/UDP代理
  47. */
  48. isStream?: boolean
  49. nginxId: number
  50. enable?: boolean
  51. http2?: boolean
  52. /**
  53. * 配置文件,当前的配置文件
  54. */
  55. confData?: string
  56. server_name: string
  57. listen: number
  58. ssl?: boolean
  59. charset?: string
  60. access_log?: string
  61. error_log?: string
  62. /**
  63. * 客户端最大的请求体大小,500m 1g
  64. */
  65. client_max_body_size?: string
  66. /**
  67. * 证书名称,平台托管的证书名称
  68. */
  69. certName?: string
  70. ssl_certificate?: string
  71. ssl_certificate_key?: string
  72. /**
  73. * eg. 5m 1h
  74. */
  75. ssl_session_timeout?: string
  76. // ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4
  77. ssl_ciphers?: string
  78. // TLSv1 TLSv1.1 TLSv1.2
  79. ssl_protocols?: string[]
  80. ssl_prefer_server_ciphers?: 'on'|'off'
  81. locations?: INginxLocation[]
  82. upstreams?: IUpstream[]
  83. streams?: INginxStream[]
  84. rewrite?: IRewrite
  85. remark?: string
  86. proxy_settings?: NgxModuleData
  87. tmp_custom_config?: string
  88. gzip?: NgxModuleData
  89. }
  90. /**
  91. * 负载均衡,跟虚拟主机放在一起吧,方便
  92. */
  93. export type IUpstream = {
  94. name: string
  95. /**
  96. * weight\backup 不能和 ip_hash 关键字一起使用。
  97. * ip_hash 或者weight 轮训
  98. */
  99. type?:'ip_hash' | 'weight'
  100. /**
  101. * 是否启用
  102. */
  103. enable?: boolean
  104. servers: {
  105. host: string
  106. port: number
  107. weight?: number
  108. /**
  109. * down:表示当前的server暂时不参与负载
  110. * weight:默认为1.weight越大,负载的权重就越大。
  111. * backup: 其它所有的非backup机器down或者忙的时候,请求backup机器。所以这台机器压力会最轻。
  112. */
  113. status?: 'down' | 'backup' | 'normal'
  114. /**
  115. * 最大失败次数,也就是最多进行 3 次尝试,默认为1
  116. */
  117. max_fails?: number
  118. /**
  119. * 超时时间,单位秒,默认值是10s
  120. */
  121. fail_timeout?: number
  122. }[]
  123. }
  124. export type INginxStream = {
  125. /**
  126. * 唯一索引
  127. */
  128. key: string
  129. listen: number
  130. /**
  131. * 与被代理服务器建立连接的超时时间为5s
  132. */
  133. proxy_connect_timeout?: number
  134. /**
  135. * 获取被代理服务器的响应最大超时时间为10s
  136. */
  137. proxy_timeout?: number
  138. /**
  139. * 当被代理的服务器返回错误或超时时,将未返回响应的客户端连接请求传递给upstream中的下一个服务器
  140. */
  141. proxy_next_upstream?: boolean
  142. /**
  143. * 总尝试超时时间为10s
  144. */
  145. proxy_next_upstream_tries?: number
  146. /**
  147. * 总尝试超时时间为10s
  148. */
  149. proxy_next_upstream_timeout?: number
  150. /**
  151. * 开启SO_KEEPALIVE选项进行心跳检测
  152. */
  153. proxy_socket_keepalive?: boolean
  154. /**
  155. * proxy_pass
  156. */
  157. proxy_pass: string
  158. /**
  159. * 是否启用
  160. */
  161. enable?: boolean
  162. }
  163. export type PNginxServer = Partial<INginxServer>
  164. /**
  165. * 键值对
  166. */
  167. export type KeyValue = {
  168. name: string
  169. value: string
  170. }
  171. /**
  172. * nginx 的location配置
  173. */
  174. export type INginxLocation = Omit<NgxModuleData, "data"> & {
  175. /**
  176. * 唯一标识
  177. */
  178. id: string
  179. /**
  180. * location的名称
  181. */
  182. name: string;
  183. /**
  184. * 匹配规则
  185. */
  186. match: {
  187. path: string
  188. regex?: string
  189. }
  190. index?: string
  191. root?: string
  192. alias?: string
  193. proxy_set_header?: IProxyHeader[]
  194. add_header?: IProxyHeader[]
  195. proxy_pass?: string
  196. // http_502 http_504 http_404 error timeout invalid_header
  197. proxy_next_upstream?: string[]
  198. //eg. 60s 1m
  199. proxy_connect_timeout?: string
  200. // 1.1
  201. proxy_http_version?: string
  202. rewrite?: IRewrite
  203. proxy_settings?: NgxModuleData
  204. gzip?: NgxModuleData
  205. tmp_custom_config?: string
  206. proxy_type?: 'proxy'| 'static' | 'returnBody' | 'other'
  207. /**
  208. * 是否为内部路由
  209. */
  210. internal?: boolean
  211. return?: {
  212. code: number
  213. content: string
  214. }
  215. /**
  216. * 临时数据,表示
  217. */
  218. __index__?: number
  219. __deploy__?: any
  220. }
  221. export type PLocation = Partial<INginxLocation>
  222. export type IProxyHeader = {
  223. name: string
  224. value: string
  225. }
  226. export type IRewrite = {
  227. /**
  228. * 正则表达式
  229. */
  230. regex: string
  231. /**
  232. * 跳转后的内容
  233. */
  234. replacement: string
  235. /**
  236. * rewrite支持的flag标记
  237. */
  238. flag: 'last' | 'break' | 'redirect' | 'permanent'
  239. }
  240. /**
  241. * nginx的自动化表单配置
  242. */
  243. export type INginxFormConfig = {
  244. server: FormColumnType[]
  245. location: FormColumnType[]
  246. addNginx: FormColumnType[]
  247. nginxSettings: FormColumnType[]
  248. nginxConf: FormColumnType[]
  249. /**
  250. * 负载均衡的
  251. */
  252. upstream: FormColumnType[]
  253. stream: FormColumnType[]
  254. }
  255. /**
  256. * 给定的初始值模板
  257. */
  258. export type INginxFormTemplate = {
  259. server: Partial<INginxServer>,
  260. location: any,
  261. addNginx: any,
  262. nginxSettings: any,
  263. nginxConf: any
  264. }