下载

    http://nginx.org/

准备环境:

        yum update 
        
        yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel

添加用户和组

    groupadd www
    useradd -g www www

配置:

./configure
–user=nobody
–group=nobody
–prefix=/usr/local/nginx
–with-http_ssl_module
–with-http_stub_status_module
–with-http_realip_module
–with-threads
–with-openssl=/usr/bin/openssl

nginx path prefix: “/usr/local/nginx” nginx binary file: “/usr/local/nginx/sbin/nginx” nginx modules path: “/usr/local/nginx/modules” nginx configuration prefix: “/usr/local/nginx/conf” nginx configuration file: “/usr/local/nginx/conf/nginx.conf” nginx pid file: “/usr/local/nginx/logs/nginx.pid” nginx error log file: “/usr/local/nginx/logs/error.log” nginx http access log file: “/usr/local/nginx/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 install

验证

/usr/local/nginx/sbin/nginx -V

创建软连接:

ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx

开机自启动

    vim /etc/init.d/nginx

init.d/nginx

赋予脚本可执行权限

    chmod a+x /etc/init.d/nginx

将nginx服务加入chkconfig管理列表

    chkconfig --add /etc/init.d/nginx
    chkconfig nginx on
    # 启动
    systemctl start nginx

配置优化

    下列配置在nginx.conf里与http节点同级

    user  www www;
    worker_processes auto;
    
    events
        {
            use epoll;
            worker_connections 51200;
            multi_accept on;
        }

http节点下加入下列配置,将会从指定目录加载配置文件

    include /usr/local/nginx/conf/servers/*.conf;