linux+nginx+tomcat集群-简单配置文件

  1. #Nginx所用用户和组,window下不指定  
  2. user  nobody;  
  3.   
  4. #工作的子进程数量(通常等于CPU数量或者2倍于CPU)  
  5. worker_processes  1;  
  6.   
  7. #错误日志存放路径  
  8. #error_log  logs/error.log;  
  9. #error_log  logs/error.log  notice;  
  10. error_log  logs/error.log  info;  
  11.   
  12. #指定pid存放文件  
  13. pid        logs/nginx.pid;  
  14.   
  15.   
  16. events {  
  17. #使用网络IO模型linux建议epoll,FreeBSD建议采用kqueue,window下不指定。  
  18. use epoll;  
  19.   
  20. #允许最大连接数    
  21. worker_connections  1024;  
  22. }  
  23.   
  24.   
  25. http {  
  26.     #mine.types内定义各文件类型映像  
  27.     include       mime.types;  
  28.   
  29.     default_type  application/octet-stream;  
  30.       
  31.     #定义日志格式  
  32.     #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '  
  33.     #                  '$status $body_bytes_sent "$http_referer" '  
  34.     #                  '"$http_user_agent" "$http_x_forwarded_for"';  
  35.   
  36.     #access_log  logs/access.log  main;  
  37.   
  38.     sendfile        on;  
  39.     #tcp_nopush     on;  
  40.   
  41.     #keepalive_timeout  0;  
  42.     keepalive_timeout  65;  
  43.   
  44.     #gzip  on;  
  45.   
  46.     #负载均衡集群设置  
  47.     upstream tomcats {  
  48.         server localhost:8080 weight=1;  
  49.         server localhost:9080 weight=1;  
  50.           
  51.         #根据ip计算将请求分配各那个后端tomcat,许多人误认为可以解决session问题,其实并不能。  
  52.         #同一机器在多网情况下,路由切换,ip可能不同 ---测试的时候可以禁止此项,轮转更明显 
  53.         ip_hash;  
  54.     }     
  55.   
  56.     server {  
  57.         listen       80;  
  58.         server_name  localhost;  
  59.   
  60.         #charset koi8-r;  
  61.   
  62.         #access_log  logs/host.access.log  main;  
  63.   
  64.         location / {  
  65.             index  index.shtml;  
  66.             proxy_pass  http://tomcats;  
  67.             proxy_set_header    X-Real-IP   $remote_addr;  
  68.             client_max_body_size    100m;  
  69.         }  
  70.   
  71. #配置动静态分离
  72. #location ~ \.(jsp)?$ {
  73.         #proxy_pass http://tomcats;
            #proxy_set_header Host $host;
            #proxy_set_header X-Real-IP $remote_addr;
            #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            #proxy_connect_timeout       100;
            #proxy_read_timeout          100;
            #proxy_send_timeout          100;
    #}
    #location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {
           
    #  expires 30d;
           
    #  root  /usr/local/nginx/html;
           
     #}

  74.         #error_page  404              /404.html;  
  75.   
  76.         # redirect server error pages to the static page /50x.html  
  77.         #  
  78.         error_page   500 502 503 504  /50x.html;  
  79.         location = /50x.html {  
  80.             root   html;  
  81.         }  
  82.   
  83.         # proxy the PHP scripts to Apache listening on 127.0.0.1:80  
  84.         #  
  85.         #location ~ \.php$ {  
  86.         #    proxy_pass   http://127.0.0.1;  
  87.         #}  
  88.   
  89.         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000  
  90.         #  
  91.         #location ~ \.php$ {  
  92.         #    root           html;  
  93.         #    fastcgi_pass   127.0.0.1:9000;  
  94.         #    fastcgi_index  index.php;  
  95.         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;  
  96.         #    include        fastcgi_params;  
  97.         #}  
  98.   
  99.         # deny access to .htaccess files, if Apache's document root  
  100.         # concurs with nginx's one  
  101.         #  
  102.         #location ~ /\.ht {  
  103.         #    deny  all;  
  104.         #}  
  105.     }  
  106.   
  107.   
  108.     # another virtual host using mix of IP-, name-, and port-based configuration  
  109.     #  
  110.     #server {  
  111.     #    listen       8000;  
  112.     #    listen       somename:8080;  
  113.     #    server_name  somename  alias  another.alias;  
  114.   
  115.     #    location / {  
  116.     #        root   html;  
  117.     #        index  index.html index.htm;  
  118.     #    }  
  119.     #}  
  120.   
  121.   
  122.     # HTTPS server  
  123.     #  
  124.     #server {  
  125.     #    listen       443;  
  126.     #    server_name  localhost;  
  127.   
  128.     #    ssl                  on;  
  129.     #    ssl_certificate      cert.pem;  
  130.     #    ssl_certificate_key  cert.key;  
  131.   
  132.     #    ssl_session_timeout  5m;  
  133.   
  134.     #    ssl_protocols  SSLv2 SSLv3 TLSv1;  
  135.     #    ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;  
  136.     #    ssl_prefer_server_ciphers   on;  
  137.     #    location / {  
  138.     #        root   html;  
  139.     #        index  index.html index.htm;  
  140.     #    }  
  141.     #}  
  142.   
  143. }  








检查nginx的配置

[root@localhost ~]# /usr/local/nginx/sbin/nginx -t -c /usr/nginx/conf/nginx.conf

四、启动测试

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
/usr/local/tomcats/tomcat-a/bin/startup.sh
/usr/local/tomcats/tomcat-b/bin/startup.sh
/usr/local/tomcats/tomcat-c/bin/startup.sh

停止服务

/usr/local/tomcats/tomcat-a/bin/shutdown.sh
/usr/local/tomcats/tomcat-b/bin/shutdown.sh
/usr/local/tomcats/tomcat-c/bin/shutdown.sh
pkill -9 nginx
重启服务
/usr/local/nginx/sbin/nginx -s reload

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值