手机版
你好,游客 登录 注册
背景:
阅读新闻

Nginx与tomcat容器的深度整合之Struts框架

[日期:2012-08-28] 来源:Linux社区  作者:fengzhanhai [字体:大 中 小]

(二)、修改nginx.conf主配置文件

user www www; #运行该服务的用户及用户组 各位同学记得1024端口下的服务要在root下启动哦

#user  nobody;

worker_processes  8; #根据你的服务器硬件性能设置

error_log  /home/www/nginx/logs/error.log; #错误日志的存放位置 很重要哦

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;

pid        /home/www/nginx/logs/nginx.pid; #服务器每次启动的id都会写到该文件哦

worker_rlimit_nofile 65535; #并发连接数上限

events {

    use epoll;             #开启epoll模式

    worker_connections  65535;

}

http {

    include       mime.types;

    default_type  application/octet-stream;

    include /home/www/nginx/conf/proxy.conf;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

    #                  '$status $body_bytes_sent "$http_referer" '

    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    #设定请求缓存

    server_names_hash_bucket_size 128;

    client_header_buffer_size 32k;

    large_client_header_buffers 8 32k;

   # client_max_body_size 8m;

    sendfile        on;

    tcp_nopush     on;

    #keepalive_timeout  0;

    keepalive_timeout  65;

    tcp_nodelay on;

    #gzip  on;

    server {

        listen       80;

        server_name  localhost;

        charset utf-8;

        index index.html index.htm index.jsp login.jsp; #设定访问的默认首页地址

        #access_log  logs/host.access.log  main;

        root /home/www/tomcat6/webapps/MMS;   #设定静态数据访问的位置

        location ~.*\.(jsp|do)$                       #设置动态数据的请求url

        {

        index index.jsp;

        proxy_pass http://localhost:8080; #动态请求转向处理

        }

        location ~.*\.(gif|jpg|jpeg|png|bmp|swf|html)$ #静态数据保存时效

        {

          expires 30d;

        }

        location ~.*\.(js|css)?$   #js和css保存时效

        {

         expires 1h;

        }

      location ~(favicon.ico) 

        {

         log_not_found off;

         expires 30d;

         break;

        }

      location /status  #统计Nginx运行状态

      {

        stub_status on;

        access_log /home/www/nginx/logs/status.log;

        auth_basic "NginxStatus";

       }

    

      # log_format access '$remote_addr - $remote_user[$time_local] "$request"'

      # '$status $body_bytes_sent "$http_referer"'

      # '"$http_user_agent" $http_x_forwarded_for';

      # access_log /home/www/nginx/logs/localhost.log access; #设定访问日志存放路径

       # location / {

       #     root   html;

       #     index  index.html index.htm;

       # }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html

        #

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            root   html;

        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80

        #

        #location ~ \.php$ {

        #    proxy_pass   http://127.0.0.1;

        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

        #

        #location ~ \.php$ {

        #    root           html;

        #    fastcgi_pass   127.0.0.1:9000;

        #    fastcgi_index  index.php;

        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

        #    include        fastcgi_params;

        #}

        # deny access to .htaccess files, if Apache's document root

        # concurs with nginx's one

        #

        #location ~ /\.ht {

        #    deny  all;

        #}

    }

    # another virtual host using mix of IP-, name-, and port-based configuration

    #

    #server {

    #    listen       8000;

    #    listen       somename:8080;

    #    server_name  somename  alias  another.alias;

    #    location / {

    #        root   html;

    #        index  index.html index.htm;

    #    }

    #}

    # HTTPS server

    #

    #server {

    #    listen       443;

    #    server_name  localhost;

    #    ssl                  on;

    #    ssl_certificate      cert.pem;

    #    ssl_certificate_key  cert.key;

    #    ssl_session_timeout  5m;

    #    ssl_protocols  SSLv2 SSLv3 TLSv1;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;

    #    ssl_prefer_server_ciphers   on;

    #    location / {

    #        root   html;

    #        index  index.html index.htm;

    #    }

    #}

}

13. stub_status统计Nginx运行状态的用法介绍

   #该设置的用法为

通过访问http://192.168.202.73/status的反回信息如下

      Active connections: 1

server accepts handled requests

      22 22 83

Reading: 0 Writing: 1 Waiting: 0

     active connections对后端发起的活动连接数

server accepts handled requests — nginx 总共处理了 22 个连接, 成功创建 22 次握手 (证明中间没有失败的), 总共处理了83 个请求 (平均每次握手处理了 4个数据请求)

reading读取到客户端的Header信息数

writing返回给客户端的Header信息数

waiting已经处理完正在等候下一次请求指令的驻留连接

14.出现如下错误在使用nginx代理访问原有服务时图片无法正常显示后台如下错误

2012/08/22 11:29:27 [error] 14389#0: *2 "/home/www/tomcat/webapps/sdmtv/index.html" is forbidden (13: Permission denied)

2012/08/2211:29:27[error]14389#0: *2 open() "/home/www/tomcat/webapps/sdmtv/favicon.ico" failed (13: Permission denied)

解决方法如下将你的tomcat目录权限设置 为chmod u+7 tomcat6

四、��续完善之压力测试篇(需要的朋友可以从其他服务器或者你的pc上部署一款功能类似的软件进行测试也可以)

1.最好下载压力测试软件webbench-1.5.tar.gz

免费下载地址在 http://linux.linuxidc.com/

用户名与密码都是www.linuxidc.com

具体下载目录在 /2012年资料/8月/28日/Nginx与tomcat容器的深度整合之Struts框架

2.解压下载后的压缩包 tar –zxvf webbench-1.5.tar.gz

3.编译和安装压力测试程序webbench make && make install

4.进行压力测试webbench -c 1000 -t 30 http://127.0.0.1/

5.通过http://192.168.202.73/status进行查看链接并发量

6.通过top和free命令查看主机资源使用情况

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款