nginx.conf 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #user nobody;
  2. worker_processes 1;
  3. #error_log logs/error.log;
  4. #error_log logs/error.log notice;
  5. #error_log logs/error.log info;
  6. #pid logs/nginx.pid;
  7. events {
  8. worker_connections 1024;
  9. }
  10. http {
  11. include mime.types;
  12. default_type application/octet-stream;
  13. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  14. # '$status $body_bytes_sent "$http_referer" '
  15. # '"$http_user_agent" "$http_x_forwarded_for"';
  16. #access_log logs/access.log main;
  17. sendfile on;
  18. tcp_nopush on;
  19. tcp_nodelay on;
  20. #keepalive_timeout 0;
  21. keepalive_timeout 65;
  22. #开启gzip
  23. gzip off;
  24. #nginx对于静态文件的处理模块,开启后会寻找以.gz结尾的文件,直接返回,不会占用cpu进行压缩,如果找不到则不进行压缩
  25. gzip_static on;
  26. #nginx做前端代理时启用该选项,表示无论后端服务器的headers头返回什么信息,都无条件启用压缩
  27. gzip_proxied expired no-cache no-store private auth;
  28. #低于10kb的资源不压缩
  29. gzip_min_length 10k;
  30. #设置压缩所需要的缓冲区大小
  31. gzip_buffers 4 16k;
  32. #设置gzip压缩针对的HTTP协议版本
  33. gzip_http_version 1.0;
  34. #压缩级别1-9,越大压缩率越高,同时消耗cpu资源也越多,建议设置在5左右。
  35. gzip_comp_level 5;
  36. #需要压缩哪些响应类型的资源,多个空格隔开。不建议压缩图片.
  37. gzip_types text/plain application/javascript application/x-javascript text/javascript text/xml text/css application/xml;
  38. #配置禁用gzip条件,支持正则。此处表示ie6及以下不启用gzip(因为ie低版本不支持)
  39. gzip_disable "MSIE [1-6]\.";
  40. #是否添加“Vary: Accept-Encoding”响应头
  41. gzip_vary on;
  42. #ip限流每秒最多1000个请求
  43. limit_req_zone $binary_remote_addr zone=myRateLimit:15m rate=1000r/s;
  44. #限制并发连接数
  45. limit_conn_zone $binary_remote_addr zone=perip:10m;
  46. limit_conn_zone $server_name zone=perserver:10m;
  47. server
  48. {
  49. listen 2080;
  50. server_name webServer;
  51. #dist上传的路径
  52. root /usr/share/nginx/html;
  53. index index.html index.htm;
  54. charset utf-8;
  55. proxy_set_header HOST $host;
  56. proxy_set_header X-Forwarded-Proto $scheme;
  57. # 获取客户端真实IP
  58. proxy_set_header X-Real-IP $remote_addr;
  59. proxy_set_header X-Real-Port $remote_port;
  60. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  61. # 支持websocket连接
  62. proxy_http_version 1.1;
  63. proxy_set_header Upgrade $http_upgrade;
  64. proxy_set_header Connection "upgrade";
  65. # 限制并发连接数
  66. #limit_conn perip 10; #每个IP最多10个并发连接
  67. # 客户端请求体限制10MB
  68. client_max_body_size 10m;
  69. # 避免访问出现 404 错误
  70. location / {
  71. root /usr/share/nginx/html; #dist上传的路径
  72. index index.html index.htm;
  73. try_files $uri $uri/ @router;
  74. }
  75. # 生产环境(http)
  76. location ^~/api {
  77. # 去除api前缀
  78. rewrite ^/api/(.*)$ /$1 break;
  79. # 代理到后端服务器
  80. proxy_pass http://flow-app:9089/;
  81. # 限流,每秒最多1000个请求
  82. limit_req zone=myRateLimit burst=100 nodelay;
  83. #每个IP最多50个并发连接
  84. limit_conn perip 50;
  85. }
  86. # 生产环境(socket)
  87. location ^~/ws {
  88. # 去除ws前缀
  89. rewrite ^/ws/(.*)$ /$1 break;
  90. # 代理到后端服务器
  91. proxy_pass http://flow-app:9089/;
  92. # 支持websocket连接
  93. proxy_http_version 1.1; # 确保使用 HTTP/1.1
  94. proxy_set_header Upgrade $http_upgrade;
  95. proxy_set_header Connection "upgrade";
  96. proxy_set_header Host $host;
  97. }
  98. error_page 500 502 503 504 /50x.html;
  99. location = /50x.html {
  100. root html;
  101. }
  102. location @router {
  103. rewrite ^.*$ /index.html last;
  104. }
  105. }
  106. # another virtual host using mix of IP-, name-, and port-based configuration
  107. #
  108. #server {
  109. # listen 8000;
  110. # listen somename:8080;
  111. # server_name somename alias another.alias;
  112. # location / {
  113. # root html;
  114. # index index.html index.htm;
  115. # }
  116. #}
  117. # HTTPS server
  118. #
  119. #server {
  120. # listen 443 ssl;
  121. # server_name localhost;
  122. # ssl_certificate cert.pem;
  123. # ssl_certificate_key cert.key;
  124. # ssl_session_cache shared:SSL:1m;
  125. # ssl_session_timeout 5m;
  126. # ssl_ciphers HIGH:!aNULL:!MD5;
  127. # ssl_prefer_server_ciphers on;
  128. # location / {
  129. # root html;
  130. # index index.html index.htm;
  131. # }
  132. #}
  133. }