ngnix配置文件如何达到负载均衡

开发 前端
ngnix配置文件不是我们想象的那么简单。其实有不少的事情需要我们注意,接下来我们就来学些有关这方面的问题,希望大家有所收获。

ngnix配置文件在使用的时候需要进行负载均衡,但是要如何才能完整这一个动作呢?下面我们就向大家介绍我的ngnix配置文件(nginx +tomcat包括 虚拟目录,负载均衡和url_Rewrite)

 

 

  1. #user nobody;  
  2. worker_processes 10;  
  3. error_log /home/weblogs/error.log crit;  
  4. #error_log logs/error.log notice;  
  5. #error_log logs/error.log info;  
  6. pid logs/nginx.pid;  
  7. worker_rlimit_nofile 51200;  
  8. events {  
  9. use epoll;  
  10. worker_connections 51200;  
  11. }  
  12. http {  
  13. include mime.types;  
  14. default_type application/octet-stream;  
  15. include proxy.conf;   
  16. log_format main '$remote_addr - $remote_user [$time_local] $request '  
  17. '"$status" $body_bytes_sent "$http_referer" '  
  18. '"$http_user_agent" "$http_x_forwarded_for"';  
  19. access_log /home/weblogs/access.log main;  
  20. server_names_hash_bucket_size 128;  
  21. #sendfile on;  
  22. #tcp_nopush on;  
  23. # tcp_nodelay on;  
  24. #keepalive_timeout 0;  
  25. #keepalive_timeout 60;  
  26. #gzip off;  
  27. #gzip_min_length 1k;  
  28. #gzip_buffers 4 8k;  
  29. #gzip_http_version 1.1;   
  30. #gzip_types text/plain application/x-javascript text/css text/html application/xml;  
  31. client_header_buffer_size 32k;  
  32. large_client_header_buffers 4 32k;  
  33. sendfile on;  
  34. tcp_nopush on;  
  35. keepalive_timeout 60;  
  36. tcp_nodelay on;  
  37. gzip on;  
  38. gzip_min_length 1k;  
  39. gzip_buffers 4 16k;  
  40. gzip_http_version 1.0;  
  41. gzip_comp_level 2;  
  42. gzip_types text/plain application/x-javascript text/css application/xml;  
  43. gzip_vary on;  
  44. upstream hljbstCms {  
  45. #ip_hash;  
  46. server localhost:8080 ;  
  47. server localhost:8081;  
  48. }  
  49. server {  
  50. server_name _;  
  51. listen 80;  
  52. charset gb2312;   
  53. location /(WEB-INF)/ {   
  54. deny all;   
  55. }   
  56. location /html/ {  
  57. index index.html;  
  58. root /home;  
  59. }  
  60. location /img/{  
  61. root /home;  
  62. }  
  63. location /res/{  
  64. root /home;  
  65. }  
  66. location / {  
  67. if ($host ~* "^[a-z0-9\-]+\.hljbst\.com$"){  
  68. rewrite ^/?$ /$host last;  
  69. rewrite ^/([a-z0-9\-]+)\.hljbst\.com/?$ http://$host/site/$1 permanent;  
  70. }   
  71. proxy_pass http://hljbstCms;  
  72. include proxy.conf;   
  73. }  
  74. location /NginxStatus {  
  75. #stub_status on;  
  76. access_log on;  
  77. auth_basic "NginxStatus";  
  78. auth_basic_user_file conf/htpasswd;  
  79. }  
  80. #error_page 404 /404.html;  
  81. # redirect server error pages to the static page /50x.html  
  82. #  
  83. error_page 500 502 503 504 /50x.html;  
  84. location = /50x.html {  
  85. root /home/ngnix/html;  
  86. }  
  87. }  

 

 

以上就是对ngnix配置文件的详细介绍。

【编辑推荐】

  1. nginx配置中运行与启动的详细介绍
  2. nginx服务器如何处理相关的图片
  3. nginx配置相关结构划分的技巧
  4. nginx配置文件实现AWStats静态页面
  5. nginx 禁止IP访问的代码编写教程
责任编辑:张浩 来源: 互联网
相关推荐

2010-04-26 10:27:39

链路负载均衡

2010-03-25 18:52:15

Nginx负载均衡

2017-05-19 14:45:01

OVN负载均衡器路由器

2019-03-15 15:02:31

F5Ngnix负载均衡

2010-04-22 12:45:05

2010-04-21 12:28:50

Oracle负载均衡

2011-11-22 21:26:59

pfSense配置Web服务器负载均衡

2010-04-20 22:19:29

tomcat负载均衡配

2014-07-28 11:37:49

NginxTomcat

2017-07-03 08:08:25

负载均衡分类

2021-11-07 14:00:16

JekyllBashAPI后端

2010-04-20 21:27:28

tomcat负载均衡配

2010-04-23 11:05:16

流量负载均衡

2011-04-28 14:56:29

XenServer负载

2012-05-07 10:17:48

2010-04-22 16:41:56

负载均衡端口规则

2010-05-10 17:52:30

实现负载均衡

2014-10-09 14:35:44

HAProxy负载均衡

2019-11-22 10:00:53

ICC配置文件Windows 10

2010-05-04 10:56:18

jboss负载均衡
点赞
收藏

51CTO技术栈公众号