码迷,mamicode.com
首页 > 其他好文 > 详细

nginx+tomcat动静分离

时间:2017-05-12 11:39:49      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:cache   ica   pid   chmod   sed   nbsp   download   mod   openssl   

一、安装nginx

yum -y install wget pcre pcre-devel openssl-devel zlib-devel lrzsz gcc gcc-c++
wget http://nginx.org/download/nginx-1.12.0.tar.gz
wget http://nginx.org/download/nginx-1.12.0.tar.gz
groupadd www
useradd -g www -s /sbin/nologin -M -r www
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_ssl_module --with-http_gzip_static_module --with-http_stub_status_module

make && make install

添加配置文件:

user  www;
worker_processes  1;

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

pid        logs/nginx.pid;


events {
    use epoll;
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    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;
    gzip_min_length 1k;
    gzip_buffers    4 16k;
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_types text/plain application/x-javascripttext/css application/xml;
    gzip_vary on;

    server {
        listen       80;
        server_name  www.test.com;

        charset utf-8;

        #access_log  logs/host.access.log  main;

        location / {
            root   /usr/local/tomcat/webapps/ROOT;
            index  index.html index.jsp  index.htm;
        }

    location ~ .*.jsp$ {
            index index.jsp;
            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_read_timeout 90;      
            proxy_buffer_size 4k;       
            proxy_buffers 6 32k;        
            proxy_busy_buffers_size 64k;
            proxy_temp_file_write_size 64k; 
        }
        location ~ .*\.(gif|jpg|png|bmp|swf)$   
        {
            expires 30d;   
        }
        location ~ .*\.(jsp|js|css)?$
        {
            expires 1d;
        }    
    
       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 Apaches document root
        # concurs with nginxs 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;
    #    }
    #}

}

 

添加启动脚本:

#!/bin/bash
# chkconfig: 345 99 20
# description: Nginx servicecontrol script
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
start)
$PROG
echo "Nginx service start success."
;;
stop)
kill -s QUIT $(cat $PIDF)
echo "Nginx service stop success."
;;
restart)
$0 stop
$0 start
;;
reload)
kill -s HUP $(cat $PIDF)
echo "reload Nginx config success."
;;
*)
echo "Usage: $0{start|stop|restart|reload}"
exit 1
esac
chmod +x /etc/init.d/nginx
service nginx restart
chkconfig nginx on

添加nginx环境:

echo -e PATH=/usr/local/nginx/sbin:$PATH >> /etc/profile
source /etc/profile

 

二、安装tomcat

 

nginx+tomcat动静分离

标签:cache   ica   pid   chmod   sed   nbsp   download   mod   openssl   

原文地址:http://www.cnblogs.com/feral/p/6844432.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!