• Nginx配置转发


    一、背景

    最近接手了内部的一个接口自动化项目,前后端分开开发的,需要在一台电脑上的调试,所以用Nginx用作转发,统一下端口,记录下。由于系统登录后不是直接跳到接口平台,要跳到一个聚合页面,从聚合页面在点击跳转到接口平台,所以其他的平台在聚合页面展示也一并转发到线上,不影响前端界面展示。

    1、我的前端地址:localhost:8082

    2、我的后端地址: localhost:9999

    3、Nginx转发配置

    1. worker_processes 1;
    2. events {
    3. worker_connections 1024;
    4. }
    5. http {
    6. include mime.types;
    7. default_type application/octet-stream;
    8. sendfile on;
    9. keepalive_timeout 65;
    10. map $http_upgrade $connection_upgrade {
    11. default keep-alive; #默认为keep-alive 可以支持 一般http请求
    12. 'websocket' upgrade; #如果为websocket 则为 upgrade 可升级的。
    13. }
    14. server {
    15. listen 80;
    16. server_name localhost;
    17. location / {
    18. root html;
    19. index index.html index.htm;
    20. }
    21. error_page 500 502 503 504 /50x.html;
    22. location = /50x.html {
    23. root html;
    24. }
    25. location /atx/{
    26. proxy_pass http://127.0.0.1:4000/;
    27. proxy_http_version 1.1;
    28. proxy_set_header Upgrade $http_upgrade; #此处配置 上面定义的变量
    29. proxy_set_header Connection $connection_upgrade;
    30. proxy_send_timeout 300;
    31. proxy_read_timeout 300;
    32. proxy_connect_timeout 300;
    33. client_max_body_size 500M;
    34. }
    35. location /beantech-report/{
    36. proxy_pass http://woody.beantechyun.cn/;
    37. proxy_http_version 1.1;
    38. proxy_send_timeout 300;
    39. proxy_read_timeout 300;
    40. proxy_connect_timeout 300;
    41. client_max_body_size 500M;
    42. }
    43. location ~ /atxprovider/(.*)/(.*)/(.*) {
    44. try_files /nonexistent @$http_upgrade;
    45. }
    46. location @websocket {
    47. proxy_pass http://$1:$2/$3;
    48. proxy_http_version 1.1;
    49. proxy_set_header Upgrade $http_upgrade;
    50. proxy_set_header Connection "upgrade";
    51. proxy_set_header Host $host;
    52. proxy_read_timeout 300;
    53. }
    54. location @ {
    55. # seems not work
    56. proxy_pass http://$1:$2/$3;
    57. }
    58. # for whatsInputAddress
    59. location ~ /atxprovider/(.*)/(.*) {
    60. proxy_pass http://$1:$2;
    61. proxy_http_version 1.1;
    62. proxy_set_header Upgrade $http_upgrade;
    63. proxy_set_header Connection "upgrade";
    64. proxy_set_header Host $host;
    65. proxy_read_timeout 300;
    66. }
    67. }
    68. #前后端调试配置转发
    69. server {
    70. listen 8080;
    71. server_name localhost;
    72. location / {
    73. proxy_pass http://localhost:8082/;
    74. proxy_http_version 1.1;
    75. proxy_set_header Upgrade $http_upgrade; #此处配置 上面定义的变量
    76. proxy_set_header Connection $connection_upgrade;
    77. proxy_send_timeout 300;
    78. proxy_read_timeout 300;
    79. proxy_connect_timeout 300;
    80. client_max_body_size 500M;
    81. }
    82. error_page 500 502 503 504 /50x.html;
    83. location = /50x.html {
    84. root html;
    85. }
    86. location /autocenter/{
    87. proxy_pass http://woody.beantechyun.cn;
    88. proxy_http_version 1.1;
    89. proxy_send_timeout 300;
    90. proxy_read_timeout 300;
    91. proxy_connect_timeout 300;
    92. client_max_body_size 500M;
    93. }
    94. location /authcenter/{
    95. proxy_pass http://woody.beantechyun.cn;
    96. proxy_http_version 1.1;
    97. proxy_send_timeout 300;
    98. proxy_read_timeout 300;
    99. proxy_connect_timeout 300;
    100. client_max_body_size 500M;
    101. }
    102. location /basecenter/{
    103. proxy_pass http://woody.beantechyun.cn;
    104. proxy_http_version 1.1;
    105. proxy_send_timeout 300;
    106. proxy_read_timeout 300;
    107. proxy_connect_timeout 300;
    108. client_max_body_size 500M;
    109. }
    110. location /msgcenter/{
    111. proxy_pass http://woody.beantechyun.cn;
    112. proxy_http_version 1.1;
    113. proxy_send_timeout 300;
    114. proxy_read_timeout 300;
    115. proxy_connect_timeout 300;
    116. client_max_body_size 500M;
    117. }
    118. location /portalcenter/{
    119. proxy_pass http://woody.beantechyun.cn;
    120. proxy_http_version 1.1;
    121. proxy_send_timeout 300;
    122. proxy_read_timeout 300;
    123. proxy_connect_timeout 300;
    124. client_max_body_size 500M;
    125. }
    126. location /testcenter/api/{
    127. proxy_pass http://127.0.0.1:9999/testcenter/api/;
    128. proxy_http_version 1.1;
    129. proxy_set_header Upgrade $http_upgrade; #此处配置 上面定义的变量
    130. proxy_set_header Connection $connection_upgrade;
    131. proxy_send_timeout 300;
    132. proxy_read_timeout 300;
    133. proxy_connect_timeout 300;
    134. client_max_body_size 500M;
    135. }
    136. location /testcenter/{
    137. proxy_pass http://127.0.0.1:8082/;
    138. proxy_http_version 1.1;
    139. proxy_send_timeout 300;
    140. proxy_read_timeout 300;
    141. proxy_connect_timeout 300;
    142. client_max_body_size 500M;
    143. }
    144. location /beantech-report/{
    145. proxy_pass http://woody.beantechyun.cn/;
    146. proxy_http_version 1.1;
    147. proxy_send_timeout 300;
    148. proxy_read_timeout 300;
    149. proxy_connect_timeout 300;
    150. client_max_body_size 500M;
    151. }
    152. location ~ /atxprovider/(.*)/(.*)/(.*) {
    153. try_files /nonexistent @$http_upgrade;
    154. }
    155. location @websocket {
    156. proxy_pass http://$1:$2/$3;
    157. proxy_http_version 1.1;
    158. proxy_set_header Upgrade $http_upgrade;
    159. proxy_set_header Connection "upgrade";
    160. proxy_set_header Host $host;
    161. proxy_read_timeout 300;
    162. }
    163. location @ {
    164. # seems not work
    165. proxy_pass http://$1:$2/$3;
    166. }
    167. # for whatsInputAddress
    168. location ~ /atxprovider/(.*)/(.*) {
    169. proxy_pass http://$1:$2;
    170. proxy_http_version 1.1;
    171. proxy_set_header Upgrade $http_upgrade;
    172. proxy_set_header Connection "upgrade";
    173. proxy_set_header Host $host;
    174. proxy_read_timeout 300;
    175. }
    176. }
    177. server {
    178. listen 8889;
    179. server_name localhost;
    180. location / {
    181. proxy_pass http://woody.beantechyun.cn/;
    182. proxy_http_version 1.1;
    183. proxy_set_header Upgrade $http_upgrade; #此处配置 上面定义的变量
    184. proxy_set_header Connection $connection_upgrade;
    185. proxy_send_timeout 300;
    186. proxy_read_timeout 300;
    187. proxy_connect_timeout 300;
    188. client_max_body_size 500M;
    189. }
    190. error_page 500 502 503 504 /50x.html;
    191. location = /50x.html {
    192. root html;
    193. }
    194. }
    195. server {
    196. listen 8891;
    197. server_name localhost;
    198. location / {
    199. proxy_pass http://woody.beantechyun.cn/;
    200. proxy_http_version 1.1;
    201. proxy_set_header Upgrade $http_upgrade; #此处配置 上面定义的变量
    202. proxy_set_header Connection $connection_upgrade;
    203. proxy_send_timeout 300;
    204. proxy_read_timeout 300;
    205. proxy_connect_timeout 300;
    206. client_max_body_size 500M;
    207. }
    208. error_page 500 502 503 504 /50x.html;
    209. location = /50x.html {
    210. root html;
    211. }
    212. }
    213. server {
    214. listen 8888;
    215. server_name localhost;
    216. location / {
    217. proxy_pass http://woody.beantechyun.cn/;
    218. proxy_http_version 1.1;
    219. proxy_set_header Upgrade $http_upgrade; #此处配置 上面定义的变量
    220. proxy_set_header Connection $connection_upgrade;
    221. proxy_send_timeout 300;
    222. proxy_read_timeout 300;
    223. proxy_connect_timeout 300;
    224. client_max_body_size 500M;
    225. }
    226. error_page 500 502 503 504 /50x.html;
    227. location = /50x.html {
    228. root html;
    229. }
    230. }
    231. }

     

  • 相关阅读:
    Python基础总结(一)
    Spring学习笔记12 面向切面编程AOP
    Halcon 模板匹配实战代码(一)
    leetcode-两数之和
    Mac的设置与优化...持续更新
    基于Java毕业设计定西扶贫惠农推介系统源码+系统+mysql+lw文档+部署软件
    数据库选型
    Opengl之面剔除
    LeetCode198:打家劫舍
    el-select的某一项选中后显示id
  • 原文地址:https://blog.csdn.net/qq_29427355/article/details/126095041