ngix安装配置

环境执行 :yum install -y zlib* pcre* gcc-c++ make lib*
1、  PCRE库的安装:  
官网:http://www.pcre.org/  
下载页面:ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ 
选择最新版本下载:  
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.32.tar.gz  解压: 
tar –zxvf pcre-8.32.tar.gz,解压目录为:pcre-8.32 
然后进入到 cd pcre-8.32,进行配置、编译、安装  
配置  
./configure或./config  编译  
make  
安装  
make install  
2、  OpenSSL库的安装  
官网:http://www.openssl.org  
下载页面:http://www.openssl.org/source/ 
选择最新版本下载  
http://www.openssl.org/source/openssl-1.0.0a.tar.gz 
解压:  
tar –zxvf openssl-1.0.0.tar.gz,解压目录为:openssl-1.0.0  
然后进入到 cd openssl-1.0.0,进行配置、编译、安装
配置 
./configure或./config  
编译  
make 
安装  
make install 
3、  nginx安装 
官网:http://nginx.org 
下载页面:http://nginx.org/en/download.html 
选择最新版本下载:  
http://nginx.org/download/nginx-1.4.4.tar.gz 
解压:  
tar –zxvf nginx-1.4.4.tar.gz,
解压目录为:nginx-1.4.4 
下载缓存清除插件:
wget http://labs.frickle.com/files/ngx_cache_purge-1.6.tar.gz
解压:
tar zxvf ngx_cache_purge-1.6.tar.gz
解压后的目录:ngx_cache_purge-1.6
然后进入到 cd nginx-1.4.4,
进行配置、
./configure --with-http_stub_status_module --prefix=/opt/nginx --add-module=../ngx_cache_purge-1.6
编译、安装

make & make install

提示gzip module requires the zlib library

yum install -y zlib-devel

Nginx的启动 
/opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf
./nginx  
如果在第三步骤没有指定设置编译文件的存放目录,
那么nginx的启动方式如下: 
cd   安装目录/objs
./nginx  
首行的   usr  后面  

改为 root 

4.测试安装是否成功:
#  ./nginx -t(如果提示下面的ok和successful成功的话,说明安装成功了)
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启动提示找不到libpcre.so.1解决方法

发现部分linux系统存有的通病。要解决这个方法非常容易

如果是32位系统

[root@l ~]#  ln -s /usr/local/lib/libpcre.so.1 /lib

如果是64位系统

[root@l ~]#  ln -s /usr/local/lib/libpcre.so.1 /lib64


进行负载均衡站点的配置:
# cd /usr/local/ nginx/conf/
# vi  nginx.conf(修改增加下面的内容)
#pidlogs/nginx.pid;------- 在第9行左右,去掉前面的“#”注释号
  (新增)
upstream localhost {------- 负载均衡站点的名称为tomcat,可以自己取
#ip_hash策略将同一IP的所有请求都转发到同一应用服务器
ip_hash;
server 192.168.0.101:81;------- web服务器的IP地址及tomcat1发布端口
server 192.168.0.101:82;------- web服务器的IP地址及tomcat2发布端口
}
server {
listen 80;------- 本机负载均衡的发布端口80
server_name localhost;------- 本机服务器名称
charset utf-8;
location / {
root html;
index index.html index.htm;
(新增) proxy_pass http://localhost ;------- 负载均衡指向的发布服务localhost

 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_set_header Host $host;

 client_max_body_size  100m;

}
}
注意:“upstream”部分要放在“server { listen80” 这部分的前面,不能放到下面去,不然会出错
proxy_pass”部分要放在localtion这部分的括号里面,且http://后面跟的名称要与上面upstream中一样
net stat -tlnp | grep :80(查看nginx端口的进程号 ps  -ef|grep nginx
kill -9 11274(杀死nginx的主进程,11274是上面查询出来的主进程号,实际环境中不一定一样)
新增测试jsp页面

SessionID:<%=session.getId()%>

<BR>

SessionIP:<%=request.getServerName()%>

<BR>

SessionPort:<%=request.getServerPort()%>

<%

out.println("This is Tomcat Server 111111!");

%>

(5)在线修改配置参数(在nginx启动的情况),并让它 重新加载,其间nginx 不用停止服务
# vi nginx.conf
kill -HUP`cat /usr/local/nginx/logs/nginx.pid`(注意cat命令两边必须要有撇号,不是单引号)
(6)设置Nginx开机自动启动:
# cd /etc/rc.d/init.d/
# vi nginx
----> 增加内容#chkconfig:35 80 10
#description:Nginx server
/usr/local/nginx/sbin/nginx
# chmod a+x nginx(授予可执行的权限)
# chkconfig --add nginx
# chkconfig nginx on

# 开启服务器读取文件的缓存,

open_file_cache max=200 inactive=2h;

open_file_cache_valid 3h;

open_file_cache_errors off;

charset utf-8;

# 判断如果是图片或swf,客户端缓存5天

location ~* ^.+.(ico|gif|bmp|jpg|jpeg|png|swf)$ {

   root   /javaing/data/web/image/;

   access_log off;

   index  index.html index.htm;

   expires 5d;

   }

# 因JS,CSS改动比较频繁,客户端缓存8小时

location ~* ^.+.(js|css)$ {

   root   /javaing/data/web/image/;

   access_log off;

   index  index.html index.htm;

   expires 8h;

   }

# 其他静态资源

location / {

   root   /javaing/data/web/image/;

   access_log off;

   expires 8h;

}

开启gzip压缩:

将#gzip  on;前面的#去掉。

<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager" memcachedNodes="n1:localhost:11211" requestUriIgnorePatte rn=".*\.(png|gif|jpg|css|js)$" sessionBackupAsync="false" sessionBackupTimeout="100" transcoderFactoryClass="de.javakaffee.web.msm.s erializer.javolution.JavolutionTranscoderFactory" copyCollectionsForSerialization="false" />   </Context> 

#禁止IP访问
server {
listen 80 default;
server_name _;
server_name www.example.com example.com
return 500;
}

参考:

http://hanqunfeng.iteye.com/blog/697696

http://wurhuangfeng.blog.163.com/blog/static/3517824120141212293395/

http://www.linuxidc.com/Linux/2012-11/74077.htm

http://www.iteye.com/topic/676347

http://www.eziep.net/details/111.html

http://www.zving.com/zsk/server/253901.shtml

http://www.cnblogs.com/phirothing/archive/2013/12/05/3459814.html

http://my.oschina.net/shootercn/blog/169761

http://freeloda.blog.51cto.com/2033581/1288553

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值