ASP源码.NET源码PHP源码JSP源码JAVA源码DELPHI源码PB源码VC源码VB源码Android源码

Windows下配置Nginx+Tomcat配置集群负载均衡(2/5)

来源:网络整理     时间:2015-10-08     关键词:Apache,include,Session

本篇文章主要介绍了"Windows下配置Nginx+Tomcat配置集群负载均衡",主要涉及到Apache,include,Session方面的内容,对于PHPjrs看球网直播吧_低调看直播体育app软件下载_低调看体育直播感兴趣的同学可以参考一下: Nginx (发音同 engine x)是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下...

DOS环境启动

运行CMD 到DOS界面

下面是一些常用的使用命令:
 Nginx -s stop         快速关闭Nginx,可能不保存相关信息,并迅速终止web服务。
 Nginx -s quit         平稳关闭Nginx,保存相关信息,有安排的结束web服务。
 Nginx -s reload       因改变了Nginx相关配置,需要重新加载配置而重载。
 Nginx -s reopen       重新打开日志文件。

 Nginx -v       查看版本
 Nginx -V       查看nginx的版本,编译器版本和配置参数

3、nginx.conf配置

  Nginx配置文件默认在conf目录,主要配置文件为nginx.conf,我们安装在D:\nginx-1.0.15、默认主配置文件为D:\nginx-1.0.15\nginx.conf。下面是nginx作为前端反向代理服务器的配置。

Nginx.conf代码

 

[plain] view plaincopy

  1. #Nginx所用用户和组,window下不指定  
  2. #user  Administrator;  
  3. #工作的子进程数量(通常等于CPU数量或者2倍于CPU)   
  4. worker_processes  2;  
  5. #错误日志存放路径  
  6. #error_log  logs/error.log;  
  7. #error_log  logs/error.log  notice;  
  8. #error_log  logs/error.log  info;  
  9. #指定pid存放文件  
  10. #pid        logs/nginx.pid;  
  11.   
  12.   
  13. events {  
  14. #使用网络IO模型linux建议epoll,FreeBSD建议采用kqueue,window下不指定。  
  15. #use epoll;  
  16.     worker_connections  2048;  
  17. }  
  18.   
  19.   
  20. http {  
  21.     include       mime.types;  
  22.     default_type  application/octet-stream;  
  23. #定义日志格式  
  24.     #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '  
  25.     #                  '$status $body_bytes_sent "$http_referer" '  
  26.     #                  '"$http_user_agent" "$http_x_forwarded_for"';  
  27.   
  28.     #access_log  logs/access.log  main;  
  29.   
  30.     sendfile        on;  
  31.     #tcp_nopush     on;  
  32.   
  33.     #keepalive_timeout  0;  
  34.     keepalive_timeout  65;  
  35.       
  36.     include    gzip.conf;  
  37. upstream localhost {     
  38.       #根据ip计算将请求分配各那个后端tomcat,许多人误认为可以解决Session问题,其实并不能。     
  39.       #同一机器在多网情况下,路由切换,ip可能不同     
  40.       #ip_hash;      
  41.       server localhost:18081;     
  42.       server localhost:8080;     
  43.      }   
  44.   
  45.     server {  
  46.         listen       80;  
  47.         server_name  localhost;  
  48.   
  49.         #charset koi8-r;  
  50.   
  51.         #access_log  logs/host.access.log  main;  
  52.   
  53.         location / {  
  54.             root   html;  
  55.             index  index.html index.htm;  
  56. proxy_pass http://localhost;  
  57.         }  
  58.   
  59.         #error_page  404              /404.html;  
  60.   
  61.         # redirect server error pages to the static page /50x.html  
  62.         #  
  63.         error_page   500 502 503 504  /50x.html;  
  64.         location = /50x.html {  
  65.             root   html;  
  66.         }  
  67.   
  68.         # proxy the PHP scripts to Apache listening on 127.0.0.1:80  
  69.         #  
  70.         #location ~ \.php$ {  
  71.         #    proxy_pass   http://127.0.0.1;  
  72.         #}  
  73.   
  74.         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000  
  75.         #  
  76.         #location ~ \.php$ {  
  77.         #    root           html;  
  78.         #    fastcgi_pass   127.0.0.1:9000;  
  79.         #    fastcgi_index  index.php;  
  80.         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;  
  81.         #    include        fastcgi_params;  
  82.         #}  
  83.   
  84.         # deny access to .htaccess files, if Apache's document root  
  85.         # concurs with nginx's one  
  86.         #  
  87.         #location ~ /\.ht {  
  88.         #    deny  all;  
  89.         #}  
  90.     }  
  91.   
  92.   
  93.     # another virtual host using mix of IP-, name-, and port-based configuration  
  94.     #  
  95.     #server {  
  96.     #    listen       8000;  
  97.     #    listen       somename:8080;  
  98.     #    server_name  somename  alias  another.alias;  
  99.   
  100.     #    location / {  
  101.     #        root   html;  
  102.     #        index  index.html index.htm;  
  103.     #    }  
  104.     #}  
  105.   
  106.   
  107.     # HTTPS server  
  108.     #  
  109.     #server {  
  110.     #    listen       443;  
  111.     #    server_name  localhost;  
  112.   
  113.     #    ssl                  on;  
  114.     #    ssl_certificate      cert.pem;  
  115.     #    ssl_certificate_key  cert.key;  
  116.   
  117.     #    ssl_Session_timeout  5m;  
  118.   
  119.     #    ssl_protocols  SSLv2 SSLv3 TLSv1;  
  120.     #    ssl_ciphers  HIGH:!aNULL:!MD5;  
  121.     #    ssl_prefer_server_ciphers   on;  
  122.   
  123.     #    location / {  
  124.     #        root   html;  
  125.     #        index  index.html index.htm;  
  126.   
  127.     #    }  
  128.     #}  
  129.   
  130. }  

代理设置如下:

[plain] view plaincopy

相关图片

相关文章