linux下安装nginx并简单配置,利用tomcat-redis共享session

nginx-1.8.0和pcre-8.35.tar.gz下载:
  http://download.csdn.net/detail/u012572955/9730860
  
  1.安装pcre:
  我这里用的是pcre-8.35.tar.gz
  解压:tar zxvf pcre-8.35.tar.gz
  进入目录:cd pcre-8.35
  编译安装:./configure
  make && make install
  
  2.安装nginx相关组件:
  安装gcc:yum install gcc
  安装gcc-c++:yum install gcc-c++
  安装openssl:yum install openssl*
  gzip 类库安装:yum install zlib zlib-devel
  
 如果yum安装找不到资源,可以使用阿里源,修改阿里源如下:
 http://blog.csdn.net/u012572955/article/details/54140460
 
  3.安装nginx:
  我这里使用的是nginx-1.8.0.tar.gz
  解压:
  tar -zxvf nginx-1.8.0.tar.gz
  进入目录:
  cd nginx-1.8.0
  配置:
  ./configure --prefix=/home/bi_user1/components/nginx-1.8.0 --with-http_stub_status_module --with-http_ssl_module --with-pcre=/home/bi_user1/components/pcre-8.35
  注意文件路径
  输出如下内容则证明ok:
  checking for zlib library ... found
 creating objs/Makefile
Configuration summary
 + using system PCRE library
 + using system OpenSSL library
 + md5: using OpenSSL library
 + sha1: using OpenSSL library
 + using system zlib library
nginx path prefix: "/usr/local/nginx-1.7.0"
 nginx binary file: "/usr/local/nginx-1.7.0/sbin/nginx"
 nginx configuration prefix: "/usr/local/nginx-1.7.0/conf"
 nginx configuration file: "/usr/local/nginx-1.7.0/conf/nginx.conf"
 nginx pid file: "/usr/local/nginx-1.7.0/logs/nginx.pid"
 nginx error log file: "/usr/local/nginx-1.7.0/logs/error.log"
 nginx http access log file: "/usr/local/nginx-1.7.0/logs/access.log"
 nginx http client request body temporary files: "client_body_temp"
 nginx http proxy temporary files: "proxy_temp"
 nginx http fastcgi temporary files: "fastcgi_temp"
 nginx http uwsgi temporary files: "uwsgi_temp"
 nginx http scgi temporary files: "scgi_temp"
# make //确定你的服务器有安装make,如果没有安装请执行yum install make


进入目录编译:
make install


4.nginx启动与配置:
进入sbin:
./nginx  为启动命令
./nginx -s stop 为停止命令
./nginx -t 为检查配置文件正确性


5.nginx简单配置:
user root;  ####打开nginx-url出现403请配置如下
error_log  logs/error.log;    
     
worker_processes 2;  
worker_rlimit_nofile 1024;  
events {  
    worker_connections 1024;  
}  
   
http {    
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '  
                                        '"$status" $body_bytes_sent "$http_referer" '  
                                        '"$http_user_agent" "$http_x_forwarded_for" '  
                                        '"$gzip_ratio" $request_time $bytes_sent $request_length';  
    access_log  logs/access.log  main;  
    include       mime.types;    
    default_type  application/octet-stream;    
     
    sendfile        on;    
    keepalive_timeout  65;    
     
    #gzip  on;    
    upstream  localhost {    
              server   10.0.4.120:7021 weight=1;    #服务器1
              server   10.0.4.120:7022 weight=1;    #服务器2
    }    
    server {    
        listen       7020;  #nginx端口
        server_name  10.0.4.120; #nginx ip
        charset utf-8;    
        location / {    
            root   html;    
            index  index.html index.htm;    
            proxy_pass       http://localhost;    
        proxy_set_header X-Real-IP $remote_addr;  
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout       1;
    proxy_read_timeout          300;
    proxy_send_timeout          300;
        }    
      
        location ~ ^/(WEB-INF)/ {     
        deny all;     
        }     
     
        error_page   500 502 503 504  /50x.html;    
        location = /50x.html {    
            root   html;    
        }    
    }    
}  


主要提升文件权限:
chmod 777 nginx-1.8.0

启动命令执行没有权限请提升对应文件权限。


附:

tomcat指定项目路径:

在conf/server.xml的host中添加如下:

<Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">


        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->


        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log." suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />
<Context path="" docBase="/home/bi_user1/components/bi_touna/CognosPro" debug="0" reloadable="true"/>
      </Host>

共享session配置:

conf/server.xml下添加:

<Valve className="com.radiadesign.catalina.session.RedisSessionHandlerValve" />
        <Manager className="com.radiadesign.catalina.session.RedisSessionManager"
                host="xxx"
                port="xxx"
                database="0"
                password="xxx"
                maxInactiveInterval="60"/>

共享session文件下载路径,jar包放在tomcat的lib目录下:

http://download.csdn.net/detail/u012572955/9729755

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值