日期:2014-05-16  浏览次数:20643 次

Linux 下 Nginx 整合 tomcat
Nginx 详细介绍请参看  百度百科链接
nginx主页下载最新版

nginx-1.0.4.tar.gz
最新的!!

到/usr/local/
tar  zxvf  nginx-1.0.4.tar.gz   
cd nginx-1.0.4  
./configure --with-http_stub_status_module --with-http_ssl_module 



此时如果如下错误
./configure: error: the HTTP cache module requires md5 functions   
from OpenSSL library.   You can either disable the module by using   
--without-http-cache option, or install the OpenSSL library into the system,   
or build the OpenSSL library statically from the source with nginx by using   
--with-http_ssl_module --with-openssl=<path> options.  


使用
yum -y install pcre-devel openssl openssl-devel   


如果无错误提示

make    
make install  


安装完成后会在/usr/local/nginx目录下

cd /usr/local/nginx/sbin/

./nginx –t  #(检查nginx.conf文件)如出现如下文字代表配置文件无问题
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

./nginx     启动服务器

访问地址(端口默认为80)出现以下文字
Welcome to nginx


./nginx  -s stop  停止服务器



整合 TOMCAT

cd /usr/local/nginx/conf/
vi proxy.conf


加入如下配置:
proxy_redirect          off;
proxy_set_header        Host $host;
proxy_set_header        X-Real-IP $remote_addr; #获取真实IP
#proxy_set_header       X-Forwarded-For   $proxy_add_x_forwarded_for; #获取代理者的真实ip
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;


保存

cd /usr/local/nginx/conf/
vi nginx.conf


http {
    include       mime.types;
    default_type  application/octet-stream;
include /usr/local/nginx/conf/proxy.conf;  #引入以上proxy.conf文件
#--------------------------------------#
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;
sendfile on;
tcp_nopush     on;
keepalive_timeout 60;
tcp_nodelay on;
#---------------------------------------#
以上为可选配置,可不写或选填


    server {
        listen       80;
        server_name  admin.zch.com;
        index  index.html index.htm;
        root /usr/local/apache-tomcat-6.0.32/webapps/admin/;      
        #为资源路径,就是说你该项目的静态页面与图片等其他东西存放

        location ~ .*.(jsp|action)$ #所有.jsp.action的页面均交由tomcat处理
        {  
        index index.jsp;
        proxy_pass http:// admin.zch.com:8080;#转向tomcat处理
        }


此处省略TOMCAT相关域名配置

配置保存过后

cd /usr/local/nginx/sbin/
./nginx -s stop
./nginx


然后按照域名访问!OK!