nginx与tomcat整合

28 09月
作者:PK|分类:工作

tomcat已经装好后

nginx 安装

安装依赖包

yum -y install openssl-devel pcre-devel zlib-devel
useradd www
tar zxvf nginx-1.5.5.tar.gz

cd nginx-1.5.5
./configure --prefix=/usr/local/nginx --user=www --group=www
make && make install

配置nginx.conf

cd /usr/local/nginx/conf
cp nginx.conf nginx.conf.bak
vi nginx.conf
#代码如下

#user  nobody;
worker_processes  auto;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  65535;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    fastcgi_intercept_errors on; #用于开启 nginx自定义404错误
    #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;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
        server_tokens off;
        gzip  on;
        gzip_min_length 1k;
        gzip_buffers 4 16k;
        gzip_comp_level 2;
        gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
        gzip_vary on;
        gzip_disable "MSIE [1-6]\.";          
    server {
        listen       80;
        server_name  localhost;
        index  index.html index.htm;
        root /web/wwwroot;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
# 静态文件交由nginx处理
    location ~ .*\.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$ 
    {
            if ($http_user_agent ~ "JikeSpider|Indy Library|Alexa Toolbar|bingbot|AskTbFXTV|AhrefsBot|CoolpadWebkit|Microsoft URL Control|YYSpider|DigExt|YisouSpider|HttpClient|MJ12bot|heritrix|EasouSpider|Ezooms|curl" )
                {
                return 403;
                }   
        expires 30d;
        valid_referers none blocked *.laomm.com laomm.com;  #加入防盗链
                if ($invalid_referer){
                        rewrite ^/ http://laomm.com/image/noper.jpg;
                        #return 403;
                                     }
    }
    location ~ .*\.(js|css)?$ 
    {
    expires 1h;
    }
    location ~ /(upload|service|teacher)/.*.(jsp|do|action|servlet)?$ { # 这些目录下面不执行jsp
    deny all;
    }
        error_page  404              /404.html; #开启自定义404错误页面,相对于根目录.

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /web/wwwroot;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
#jsp等动态文件交给tomcat处理        
    location ~ (\.jsp)|(\.*)|(\.action)|(\.servlet)$ {
    proxy_pass http://127.0.0.1:8080; 
    proxy_redirect off;
    proxy_set_header HOST $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    client_max_body_size 10m;
    client_body_buffer_size 128k;
    proxy_connect_timeout 90;
    proxy_send_timeout 90;
    proxy_read_timeout 90;
    proxy_buffer_size 4k;
    proxy_buffers 4 32k;
    proxy_busy_buffers_size 64k;
    proxy_temp_file_write_size 64k;
    }
        # 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 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

#重新载入nginx配置文件
/usr/local/nginx/sbin/nginx -s reload

把tomcat权限改成www运行

chown www -R /usr/local/tomcat
vi /soft/m.sh
#!/bin/sh
JAVA_HOME=/usr/local/jdk
JRE_HOME=/usr/local/jdk/jre
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
export JAVA_HOME JRE_HOME PATH CLASSPATH
su -c /usr/local/tomcat/bin/startup.sh www

设置这个脚本开启启动,

chmod +x /soft/m.sh
echo "/soft/m.sh">/etc/rc.local
浏览676 评论0
返回
目录
返回
首页
Windows 性能监视器工具 windows 2003 创建硬链接