在centos5上编译安装nginx

这不是什么复杂的工作,记在这里做个备忘

1,从http://nginx.org/en/download.html下载nginx的源代码,我用的是1.0.3版本的

2,升级各种基础库和支持软件 
yum -y install gcc openssl-devel pcre-devel zlib-devel


3,解压缩, tar zvxf nginx-1.0.3.tar.gz

4, 进入解压缩之后的nginx-1.0.3目录, 使用默认选项安装ngix,
./configure; make; make install;


5,配置nginx转发请求给tomcat
    进入默认的安装目录/usr/local/nginx/conf,编辑nginx.conf文件,在#gzip on之后新开一行,加上一段upstream配置,例如这样
 
    upstream tomcat_server {
      ip_hash;
      server 127.0.0.1:18000;
      server 127.0.0.1:19000;
    }
  

    使用ip_hash是为了保证来自同一个用户的请求能始终转发到同一台tomcat服务器上。然后修改 location / { 里面的配置,在index  index.html index.htm;之后新开一行,加上下面这段
   
            proxy_set_header        Host $host;
            proxy_set_header        X-Real-IP $remote_addr;            
            proxy_pass http://tomcat_server;
    

   这个,用户的原始请求的ip就会在http头信息里以X-Real-IP的名字传递给tomcat服务器。

6,启动nginx
     设置完毕后,运行/usr/local/nginx/sbin/nginx -t来检查配置文件是否正确,如果没有问题,会有下面的两行提示
   
引用
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

      然后运行/usr/local/nginx/sbin/nginx即可
   



猜你喜欢

转载自swordinhand.iteye.com/blog/1112174
今日推荐