1.安装基础环境包(如果已安装,可更新) yum -y :自动选择y

     yum -y install openssl*
        yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel
        yum -y install libxml2 libxml2-devel zlib zlib-devel ncurses ncurses-devel curl curl-devel
        yum -y install gd gd2 gd-devel gd2-devel
        yum –y install gcc gcc-c++

  注:本人在安装过程发生一个错误,提示 

/var/run/yum.pid 已被锁定,PID 为 xxxx 的另一个程序正在运行

 该解决办法:直接在终端运行 rm -f /var/run/yum.pid 将该文件删除,然后再次运行yum。

2. 安装 pcre

     1 )  使用rz命令从主机下载pcre-8.38.zip文件(前提是主机上有该文件)

  2) 解压pcre-8.38.zip

unzip pcre-8.38.zip  

  3)安装   

  cd pcre-8.38
   ./configure     
   make
   make install

3.  下载Nginx1.9.9 ,解压安装 (注:本人习惯将下载位置放于/tmp 下)

复制代码
     wget http://nginx.org/download/nginx-1.9.9.tar.gz
     tar -zxvf nginx-1.9.9.tar.gz 
     cd nginx-1.9.9/usr/sbin/groupadd www   
     /usr/sbin/useradd -g www www   
   ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/application/pcre
   #注: 由于安装pcre没有指定目录,因此不用指定--with-pcre。若安装pcre有指定路径,--with-pcre也要指定路径
   make
   make install
复制代码

4.  配置Nginx

复制代码
cd /usr/local/nginx/conf
    -> vim nginx.conf

        user www www;
        worker_processes  auto;
        worker_rlimit_nofile 204800;

        #error_log  logs/error.log;
        #error_log  logs/error.log  notice;
        #error_log  logs/error.log  info;
        error_log   /data/logs/nginx_error/nginx_error.log  crit;

        pid  logs/nginx.pid;

        events {
            use epoll; # Linux best model
            worker_connections  2048000; # max thread erery process 
            multi_accept on;
        }

        http {
            #close the nginx version
            server_tokens   off;

            sendfile        on;
            tcp_nopush      on;
            tcp_nodelay     on;

            include       mime.types;
            default_type  application/octet-stream;
            charset UTF-8;

            # ssi on;
            # ssi_silent_errors on;
            # ssi_types text/shtml;


            #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
            #                  '$status $body_bytes_sent "$http_referer" '
            #                  '"$http_user_agent" "$http_x_forwarded_for"';

            #access_log  logs/access.log  main;

            keepalive_timeout  65;
            client_header_timeout 10;
            client_body_timeout 10;
            reset_timedout_connection on;
            send_timeout 10;

            limit_conn_zone $binary_remote_addr zone=addr:5m;
            limit_conn addr 100;

            client_header_buffer_size 32k;
            large_client_header_buffers  4 4k;

            server_names_hash_bucket_size 128;
            client_max_body_size 100M;

            fastcgi_connect_timeout 300;
            fastcgi_send_timeout 300;
            fastcgi_read_timeout 300;
            fastcgi_buffer_size 64k;
            fastcgi_buffers 4 64k;
            fastcgi_busy_buffers_size 128k;
            fastcgi_temp_file_write_size 256k;

            gzip on;
            gzip_disable        "MSIE [1-6]\.";
            gzip_proxied        expired no-cache no-store private auth;
            gzip_min_length  1k;
            gzip_comp_level 4;
            gzip_buffers     4 16k;
            gzip_http_version 1.0;
            gzip_types       text/plain application/x-javascript text/css application/xml;
            gzip_vary on;

            server 
            {
                listen 80;
                server_name _;
                return 500;
            }

            include vhosts/*.conf;

        }

     mkdir vhosts
     chmod 777 vhosts
复制代码

 

附 : 一些nginx有关基本命令

  -> /usr/local/nginx/sbin/nginx 启动
    -> /usr/local/nginx/sbin/nginx -t 测试配置文件
    -> /usr/local/nginx/sbin/nginx -s reload 重启
    -> /usr/local/nginx/sbin/nginx -v 查看nginx版本
    -> /usr/local/nginx/sbin/nginx -V 查看nginx版本,及配置信息
    -> netstat -antlp | grep 80     nginx占用80端口,检查是否启动
    -> ps -ef | grep nginx 命令ps查找nginx的主进程号,检查是否启动(假设主进程号为3514)
    -> kill -QUIT 3514     从容停止
    -> kill -TERM 3514     快速停止
    -> kill -9 3514         强制停止,只关闭一个主进程号,其余进程号仍在运行
    -> kill -9 3514 3515 3525     强制关闭nginx所有进程号
    -> kill -HUP 3514 平滑重启