所有的安装包可以去以下地址下载,或者自行去官网下载,下面都有介绍.
所有安装包地址:http://download.csdn.net/detail/carboncomputer/9238037
原文地址:http://www.cnblogs.com/zhongshengzhen/p/nginx.html

1、下载PCRE, 是一个用C语言编写的正则表达式函数库

[root@localhost pcre-8.36]# cd /tmp/download/

[root@localhost download]# tar zxvf pcre-8.36.tar.gz
 
2、下载zlib库
[root@localhost pcre-8.36]# cd /tmp/download/
[root@localhost download]# wget http://ncu.dl.sourceforge.net/project/libpng/zlib/1.2.8/zlib-1.2.8.tar.gz
[root@localhost download]# tar -zxvf zlib-1.2.8.tar.gz cd zlib-1.2.8
4、下载SSL
[root@localhost zlib-1.2.8]# cd ..
[root@localhost download]# wget http://www.openssl.org/source/openssl-1.0.1p.tar.gz
[root@localhost download]# cd openssl-1.0.1c
[root@localhost openssl-1.0.1c]# tar -zxvf openssl-1.0.1c.tar.gz
 
5、下载nginx
[root@localhost download]# wget http://nginx.org/download/nginx-1.2.8.tar.gz
[root@localhost download]# tar -zxvf nginx-1.2.8.tar.gz
 
6、安装
[root@localhost download]mv pcre-8.36 /usr/local/
[root@localhost download]mv zlib-1.2.8 /usr/local/
[root@localhost download]mv openssl-1.0.1c /usr/local/
[root@localhost download]mv nginx-1.2.8 /usr/local/
 
[root@localhost download]cd /usr/local/
 
[root@localhost local]# cd pcre-8.36
[root@localhost pcre-8.36]# ./configure&&make&&make install
 
[root@localhost pcre-8.36] cd ../zlib-1.2.8
[root@localhost zlib-1.2.8]# ./configure && make && make install
 
[root@localhost zlib-1.2.8]# cd ../openssl-1.0.1c
[root@localhost openssl-1.0.1c]# ./config && make && make install
 
[root@localhost openssl-1.0.1c]# cd ../nginx-1.2.8
[root@localhost nginx-1.2.8]# ./configure --prefix=/usr/local/nginx && make && make install
 
7、启动nginx
[root@localhost nginx]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
 
8、测试
在确保可以连接到服务器的电脑上,浏览器输入装了nginx的机器的ip地址,会看到Welcome to nginx!的提示说明安装配配置成功了。
 
 
 
 
9、设置开机自动启动(shell脚本处理)
[root@localhost logs]# vi /etc/init.d/nginx
 
添加以下shell脚本。
 
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
#              It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/var/run/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
   echo "nginx already running...."
   exit 1
fi
   echo -n $"Starting $prog: "
   daemon $nginxd -c ${nginx_config}
   RETVAL=$?
   echo
   [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
   return $RETVAL
}
# Stop nginx daemons functions.
stop() {
        echo -n $"Stopping $prog: "
        killproc $nginxd
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
# reload nginx service functions.
reload() {
    echo -n $"Reloading $prog: "
    #kill -HUP `cat ${nginx_pid}`
    killproc $nginxd -HUP
    RETVAL=$?
    echo
}
# See how we were called.
case "$1" in
start)
        start
        ;;
stop)
        stop
        ;;
reload)
        reload
        ;;
restart)
        stop
        start
        ;;
status)
        status $prog
        RETVAL=$?
        ;;
*)
        echo $"Usage: $prog {start|stop|restart|reload|status|help}"
        exit 1
esac
exit $RETVAL
保存后,设置权限让所有人可以操作。
[root@localhost ~]# chmod a+x /etc/init.d/nginx 
[root@localhost logs]#  /etc/init.d/nginx status
nginx (pid 2417 2416) is running...
[root@localhost logs]#  /etc/init.d/nginx stop
Stopping nginx: [  OK  ]
[root@localhost logs]#  /etc/init.d/nginx start
Starting nginx: [  OK  ]
[root@localhost logs]#  /etc/init.d/nginx status
nginx (pid 2454 2452) is running...
[root@localhost ~]# vi /etc/rc.local
添加:
/etc/init.d/nginx start
 
重启电脑就会生效。
注意:脚本里面关于启动目录的,如果你的安装地址不一样,要进行修改。
 
负载均衡配置:
现有两部服务器:
192.168.137.197     (按照以上操作安装有nginx,作为转发机,虚拟机)
192.168.137.33     (无安装nginx,运行有测试用的web工程,虚拟机)
10.10.33.59    (无安装nginx,运行有测试用的web工程,本地电脑地址)
,运行有测试用的web工程
127.0.0.1 web_app
[root@a conf]# vi /usr/local/nginx/conf/nginx.conf
配置如下展示:
worker_processes 8;
pid /usr/local/nginx/nginx.pid;
worker_rlimit_nofile 102400;
events
{
use epoll;
worker_connections 102400;
}
http
{
  include       mime.types;
  default_type  application/octet-stream;
  fastcgi_intercept_errors on;
  charset  utf-8;
  server_names_hash_bucket_size 128;
  client_header_buffer_size 4k;
  large_client_header_buffers 4 32k;
  client_max_body_size 300m;
  sendfile on;
  tcp_nopush     on;

keepalive_timeout 60;

tcp_nodelay on;
  client_body_buffer_size  512k;

proxy_connect_timeout    5;
  proxy_read_timeout       60;
  proxy_send_timeout       5;
  proxy_buffer_size        16k;
  proxy_buffers            4 64k;
  proxy_busy_buffers_size 128k;
  proxy_temp_file_write_size 128k;

  gzip on;
  gzip_min_length  1k;
  gzip_buffers     4 16k;
  gzip_http_version 1.1;
  gzip_comp_level 2;
  gzip_types       text/plain application/x-javascript text/css application/xml;
  gzip_vary on;

###2012-12-19 change nginx logs
log_format  main  '$http_x_forwarded_for - $remote_user [$time_local] "$request" '
              '$status $body_bytes_sent "$http_referer" '
              '"$http_user_agent"  $request_time $remote_addr';

upstream web_app {
server 192.168.137.197:8080 weight=1 max_fails=2 fail_timeout=30s;
server 192.168.137.33:8080 weight=1 max_fails=2 fail_timeout=30s;
server 10.10.33.59:8080 weight=1 max_fails=2 fail_timeout=30s;
}

####chinaapp.sinaapp.com
server {  
    listen 80; 
    server_name  chinaapp.sinaapp.com;
    index index.jsp index.html index.htm;
    #发布目录/data/www
    root  /data/www;

location / 
    {  
    proxy_next_upstream http_502 http_504 error timeout invalid_header;
    proxy_set_header Host  $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://web_app;
    expires      3d;
    }  
  }  
}

设置host:
[root@a conf]# vi /etc/hosts
添加hosts:
127.0.0.1 web_app

启动nginx
[root@localhost nginx]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
 
启动三部服务器的web应用:
在192.168.137.197执行指令:
[root@a PROGRAM]# curl "http://web_app/index.jsp"
测试结果如下:
 
 
 
常见问题及解决办法:
1、安装PCRE时提示configure: error: You need a C++ compiler for C++ support.
原因是没有安装c++编译器,采用下面的命令安装:
[root@localhost pcre-8.37]# yum install -y gcc gcc-c++
 
2、启动nginx失败
[root@localhost nginx]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
/usr/local/nginx/sbin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory
原因是64bit的系统,但是默认取了/usr/local/lib里面的包
检查方法:
[root@localhost nginx]# cd /usr/local/
[root@localhost local]# ls /lib64/ |grep pcre
libpcre.so.0
libpcre.so.0.0.1
[root@localhost local]# ls /lib/ |grep pcre
说明缺失的包在lib64
设置软连接来解决:
[root@localhost local]# ln -s /lib64/libpcre.so.0.0.1 /lib64/libpcre.so.1
[root@localhost local]# cd nginx
[root@localhost nginx]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
3、启动报错:
报错:nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
解决办法:sudo fuser -k 80/tcp
端口被占用,关闭占用端口
 
 

CentOS6.5安装nginx及负载均衡配置的更多相关文章

  1. 傻瓜式安装nginx以及负载均衡配置

    概述 需求 做了一个对内的http api应用.由于只有一台服务器,考虑到升级问题(即升级时会造成几秒钟用户访问不了),决定搭一个nginx,公共端口:9999,部署2套应用,端口:9981,9982 ...

  2. nginx四层负载均衡配置

    nginx四层负载均衡配置代理Mysql集群 环境如下: ip 192.168.6.203 Nginx ip 192.168.6.*(多台) Mysql 步骤一 查看Nginx是否安装stream模块 ...

  3. Nginx + Tomcat 负载均衡配置详解

    Nginx常用操作指南一.Nginx 与 Tomcat 安装.配置及优化1. 检查和安装依赖项 yum -y install gcc pcre pcre-devel zlib zlib-devel o ...

  4. Docker安装nginx以及负载均衡

    首先在linux系统中新建一个data文件夹进行nginx容器的创建--即为:mkdir data. 一:第一次 1 第一步: 使用 docker pull nginx将nginx的镜像从仓库下载下来 ...

  5. [转]CENTOS 6.5 配置YUM安装NGINX+服务器负载均衡

    原文连接: CENTOS 6.5 配置YUM安装NGINX  http://blog.sina.com.cn/s/blog_69f467b70102uyux.html 参考博文: Centos下安装. ...

  6. centos6 Nginx+Tomcat负载均衡配置

    一.Nginx简介 Nginx是一个web服务器也可以用来做负载均衡及反向代理使用,目前使用最多的就是负载均衡,具体简介我就不介绍了百度一下有很多,下面直接进入安装步骤 二.Nginx安装 1.下载N ...

  7. Nginx+tomcat负载均衡配置

    Nginx+tomcat是目前主流的java web架构,如何让nginx+tomcat同时工作呢,也可以说如何使用nginx来反向代理tomcat后端均衡呢?直接安装配置如下: 1.JAVA JDK ...

  8. Linux上安装nginx+tomcat负载均衡

    1.Ngnix Nginx (发音同 engine x)是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行.  其特点是占有内 ...

  9. Linux记录-Nginx+Tomcat负载均衡配置

    Nginx负载均衡配置及策略: 轮询(默认) 优点:实现简单缺点:不考虑每台服务器的处理能力配置示例如下:upstream www.xxx.com {# 需要负载的server列表server www ...

随机推荐

  1. MAC下编译FFMPEG

    1.下载ffmpeg,我使用xcode自带的git下载. 或者直接下载压缩包: 2.下载gas-preprocessor脚本 https://raw.github.com/mansr/gas-prep ...

  2. IDirect3DDevice9::GetRenderTargetData

    翻译自DXSDK 将渲染目标数据从设备内存拷贝到系统内存. HRESULT GetRenderTargetData(  [in]  IDirect3DSurface9 *pRenderTarget,  ...

  3. 【HDOJ】5296 Annoying problem

    LCA+RMQ.挺不错的一道题目. 思路是如何通过LCA维护费用.当加入新的点u是,费用增量为dis[u]-dis[lca(u, lower_u)] - dis[lca(u, greater_u)] ...

  4. 深入理解memcached

    网上有5篇介绍memcached的文章,写的挺好,这里转过来. memcached完全剖析–1. memcached的基础 memcached全面剖析–2.理解memcached的内存存储 memca ...

  5. poj 2299 Ultra-QuickSort (归并排序 求逆序数)

    题目:http://poj.org/problem?id=2299 这个题目实际就是求逆序数,注意 long long 上白书上的模板 #include <iostream> #inclu ...

  6. MYI 文件内容

    参考 http://blog.itpub.net/703656/viewspace-1018470/ 创建表结构 create table test(name char(20), age int, c ...

  7. UVA 1324 The Largest Clique 最大团(强连通分量,变形)

    题意:给一个有向图,要求找出一些点,使得这些点中的任意点对,要么可以互通,要么单向可达. 思路:最低只要求单向可达即可,即a->b都可以算进去. 强连通分量内的点肯定是满足要求的,可以全选,但是 ...

  8. c语言关键字总结

    1.关键字变更历史 1999年12月16日,ISO推出了C99标准,该标准新增了5个C语言关键字: inline restrict _Bool _Complex _Imaginary(注意bool 从 ...

  9. 关于触发器、存储过程和DBlink的综合运用 (转)

    关于触发器.存储过程和DBlink的综合运用 需求描述: 需要在两个不同oracl数据库实例中进行数据逻辑处理.如果A实例中的表有新数据插入或者数据更新,那么在B实例中执行与之相关的存储过程. 先假设 ...

  10. 在Sql Server 查询分析器里使用事务

    declare @updatecount int begin TRAN DECLARE @tbid INTSELECT @tbid=iMax FROM tbID WHERE strName='ipcc ...