编译安装Nginx

  1. 先安装编译过程中所需依赖包
    # yum -y install gcc pcre-devel openssl-devel zlib-devel
  2. jemalloc(更好的内存管理)
    # wget http://www.canonware.com/download/jemalloc/jemalloc-4.0.4.tar.bz2
    # tar -jxvf jemalloc-4.0.4.tar.bz2 && cd jemalloc-4.0.4
    # ./configure
    # make && make install
    # echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf
    # ldconfig
    备注:如果解压失败,遇到如下问题
    tar (child): lbzip2: Cannot exec: No such file or directory
    tar (child): Error is not recoverable: exiting now
    tar: Child returned status
    tar: Error is not recoverable: exiting now

    解决方法:安装bzip2
    # yum install bzip2

  3. lua模块
    lua-nginx-module来自大牛agentzh的开源项目,在Nginx中嵌入Lua语言,使之可以支持强大Lua语法
    1. 下载LuaJIT2.0并安装
    切换到上级目录  # cd ..
    # wget http://luajit.org/download/LuaJIT-2.0.4.tar.gz
    # tar -zxvf LuaJIT-2.0.4.tar.gz && cd LuaJIT-2.0.4
    # make && make install
    2. 下载并解压ngx_devel_kit和lua-nginx-module
    切换到上级目录  # cd ..
    下载ngx_devel_kit-0.2.19.tar.gz (https://codeload.github.com/simpl/ngx_devel_kit/tar.gz/v0.2.19)
    解压  # tar -zxvf ngx_devel_kit-0.2.19.tar.gz
    下载lua-nginx-module-0.9.20rc2.tar.gz (https://codeload.github.com/openresty/lua-nginx-module/tar.gz/v0.9.20rc2)
    解压  # tar -zxvf lua-nginx-module-0.9.20rc2.tar.gz
    3. 导入环境变量
    # export LUAJIT_LIB=/usr/local/lib
    # export LUAJIT_INC=/usr/local/include/luajit-2.0
  4. ngx_cache_purge模块(Nginx清除缓存模块)
    切换到上级目录  # cd ..
    下载 # wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz
    解压 # tar -zxvf ngx_cache_purge-2.3.tar.gz
  5. 下载Nginx源码包
    # wget http://nginx.org/download/nginx-1.9.9.tar.gz
  6. 解压Nginx源码包
    # tar -zxvf nginx-1.9.9.tar.gz && cd 
    nginx-1.9.9
  7. 编译安装Nginx
    # ./configure \
        --sbin-path=/usr/local/nginx/nginx \
        --conf-path=/usr/local/nginx/nginx.conf \
        --pid-path=/var/run/nginx.pid \
        --user=nginx \
        --group=nginx \
        --with-http_ssl_module \
        --with-http_stub_status_module \
        --with-threads \
        --with-stream \
        --with-stream_ssl_module \
        --with-ipv6 \
        --with-http_v2_module \
        --add-module=../ngx_cache_purge-2.3 \
        --add-module=../lua-nginx-module-0.9.20rc2 \
        --add-module=../ngx_devel_kit-0.2.19 \
        --with-ld-opt='-ljemalloc' \
        --with-cc-opt='-O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'

    # make -j2 && make install

  8. 创建Nginx启动脚本
    # vi /etc/init.d/nginx
    #!/bin/sh
    #
    # nginx - this script starts and stops the nginx daemon
    #
    # chkconfig: -
    # description: NGINX is an HTTP(S) server, HTTP(S) reverse \
    # proxy and IMAP/POP3 proxy server
    # processname: nginx
    # config: /etc/nginx/nginx.conf
    # config: /etc/sysconfig/nginx
    # pidfile: /var/run/nginx.pid # Source function library.
    . /etc/rc.d/init.d/functions # Source networking configuration.
    . /etc/sysconfig/network # Check that networking is up.
    [ "$NETWORKING" = "no" ] && exit nginx="/usr/local/nginx/nginx"
    prog=$(basename $nginx) NGINX_CONF_FILE="/usr/local/nginx/nginx.conf" [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx lockfile=/var/lock/subsys/nginx make_dirs() {
    # make required directories
    user=`$nginx -V >& | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
    if [ -z "`grep $user /etc/passwd`" ]; then
    useradd -r -M -s /sbin/nologin $user
    fi
    options=`$nginx -V >& | grep 'configure arguments:'`
    for opt in $options; do
    if [ `echo $opt | grep '.*-temp-path'` ]; then
    value=`echo $opt | cut -d "=" -f `
    if [ ! -d "$value" ]; then
    # echo "creating" $value
    mkdir -p $value && chown -R $user $value
    fi
    fi
    done
    } start() {
    [ -x $nginx ] || exit
    [ -f $NGINX_CONF_FILE ] || exit
    make_dirs
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq ] && touch $lockfile
    return $retval
    } stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq ] && rm -f $lockfile
    return $retval
    } restart() {
    configtest || return $?
    stop
    sleep
    start
    } reload() {
    configtest || return $?
    echo -n $"Reloading $prog: "
    killproc $nginx -HUP
    RETVAL=$?
    echo
    } force_reload() {
    restart
    } configtest() {
    $nginx -t -c $NGINX_CONF_FILE
    } rh_status() {
    status $prog
    } rh_status_q() {
    rh_status >/dev/null >&
    } case "$1" in
    start)
    rh_status_q && exit
    $
    ;;
    stop)
    rh_status_q || exit
    $
    ;;
    restart|configtest)
    $
    ;;
    reload)
    rh_status_q || exit
    $
    ;;
    force-reload)
    force_reload
    ;;
    status)
    rh_status
    ;;
    condrestart|try-restart)
    rh_status_q || exit
    ;;
    *)
    echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
    exit
    esac
  9. 设置Nginx服务开机自启动
    # chmod +x /etc/init.d/nginx
    # chkconfig nginx on
  10. 开通防火墙
    # firewall-cmd --permanent --add-service={http,https}
    # firewall-cmd --reload
  11. 新建网站根目录并更改SELinux类型
    # mkdir -p /data/www && chcon -t httpd_sys_content_t -R /data/www/
  12. 创建conf目录,用于存放Nginx各类配置文件
    # mkdir /usr/local/nginx/conf
  13. 创建gzip.conf配置文件
    # vi /usr/local/nginx/conf/gzip.conf
    gzip               on;
    gzip_min_length 1k;
    gzip_buffers 16k;
    gzip_http_version 1.0;
    gzip_comp_level ;
    gzip_proxied any;
    gzip_vary on;
    gzip_disable "MSIE [1-6]\.";
    gzip_types
    text/plain
    application/x-javascript
    text/css
    application/xml
    text/javascript
    application/x-httpd-php
    image/jpeg
    image/gif
    image/png;
  14. 创建no-default配置文件
    # vi /usr/local/nginx/conf/no-default.conf
    # Drop requests for unknown hosts
    #
    # If no default server is defined, nginx will use the first found server.
    # To prevent host header attacks, or other potential problems when an unknown
    # servername is used in a request, it's recommended to drop the request
    # returning "no response". server {
    listen default_server;
    return ;
    }
  15. 创建example.com配置文件(假设example.com的站点在这台服务器上)
    # vi /usr/local/nginx/conf/example.com.conf
    server {
    listen [::]:;
    listen ; server_name www.example.com;
    return $scheme://example.com$request_uri;
    } server {
    listen [::]:;
    listen ; server_name example.com;
    root /data/www/example.com; error_page /.html; location ~ \.php$ {
    fastcgi_pass 127.0.0.1:;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    } location ~ \.jsp$ {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_pass http://127.0.0.1:8080;
    }
    }
  16. 修改Nginx配置文件
    # vi /usr/local/nginx/nginx.conf
    user  nginx nginx;
    worker_processes auto; error_log logs/error.log warn; pid /var/run/nginx.pid; worker_rlimit_nofile ; events {
    worker_connections ;
    } http {
    include mime.types;
    default_type application/octet-stream; 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; charset utf-;
    index index.html index.htm index.php index.jsp; sendfile on;
    tcp_nopush on;
    server_tokens off; keepalive_requests ;
    keepalive_timeout ; include conf/*.conf;
    }
  17. 启动Nginx
    # service nginx start

备注:

详细编译选项:

./configure \
--prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-ipv6 \
--with-http_spdy_module \
--with-cc-opt='-O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'

yum安装Nginx

  1. 添加Nginx源
    # wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
    # rpm -Uvh nginx-release-centos-7-0.el7.ngx.noarch.rpm
  2. 安装Nginx
    # yum install nginx

对应不同系统的RPM包
RedHat6(64bit)    http://nginx.org/packages/rhel/6/x86_64/RPMS/nginx-1.8.0-1.el6.ngx.x86_64.rpmCentOS7(64bit)    http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.8.0-1.el7.ngx.x86_64.rpm

RedHat7安装Nginx及第三方模块的更多相关文章

  1. Windows 编译安装 nginx 服务器 + rtmp 模块

    有关博客: <Windows 编译安装 nginx 服务器 + rtmp 模块>.<Ubuntu 编译安装 nginx>.<Arm-Linux 移植 Nginx> ...

  2. Day 16 : Python 时间模块[time,]datetime[]及第三方模块的下载与安装

    在进行python程序开发时,除了可以使用python内置的标准模块外,还右许多第三方模块使用,可以在python官网找到. 在使用第三方模块时,需要下载并安装此模块,然后就可以使用标准模块一样导入并 ...

  3. OSX安装nginx和rtmp模块(rtmp直播服务器搭建)

    1.安装Homebrew,执行命令 1 ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/ma ...

  4. yum安装nginx添加upstream_check_module模块

    下载模块 upstream_check_module 查看yum安装nginx版本信息 # nginx -V nginx version: nginx/1.17.0 built by gcc 4.8. ...

  5. 已安装nginx动态添加模块

    说明:已经安装好的nginx,需要添加一个未被编译安装的模块,需要怎么弄呢? 具体:这里以安装第三方ngx_http_google_filter_module模块为例nginx的模块是需要重新编译ng ...

  6. ubuntu系统下安装pip3及第三方库的安装

    ubuntu系统下会自带python2.x和python3.x坏境,不需要我们去安装.并且ubuntu系统下还会自动帮助我们安装python2.x坏境下的pip安装工具, 但是没有python3.x坏 ...

  7. 如何安装nginx第三方模块

    nginx文件非常小但是性能非常的高效,这方面完胜apache,nginx文件小的一个原因之一是nginx自带的功能相对较少,好在nginx允许第三方模块,第三方模块使得nginx越发的强大. 在安装 ...

  8. nginx 增加 lua模块

    Nginx中的stub_status模块主要用于查看Nginx的一些状态信息. 本模块默认是不会编译进Nginx的,如果你要使用该模块,则要在编译安装Nginx时指定: ./configure –wi ...

  9. Linux、Docker安装Nginx

    Docker安装Nginx #docker images nginx #docker search nginx #docker pull nginx #docker run -it -p 8084:8 ...

随机推荐

  1. 加JENKINS的SLAVE节点(LINUX)要注意的事项

    从昨天下午到现在,终于解决了所有的问题.作如下记录要点: 1,从节点只要建好目录,JENKINS的包,MASTER会推送过来. 2,ANT,MAVEN之类的,要配置好环境变量,PROFILE.D .B ...

  2. [转贴]C++、C#写的WebService相互调用

    以下宏文(原文在 http://blog.sina.com.cn/s/blog_4e7d38260100ade4.html),是转贴并进行了修饰编辑: 首先感谢永和兄提供C++的WebService服 ...

  3. AT&T汇编中系统调用和C函数调用的使用

    我的博客:www.while0.com 区别: 系统调用的参数存储在寄存器中,函数调用的则存储在堆栈中. 系统调用使用中断方式,函数调用使用call指令 相同之处: 都有返回值和输入值 返回值都存储在 ...

  4. DIV 清除样式浮动万能代码

            .talk {             width: 100%;             margin: 10px 0;         }         .talk:after { ...

  5. bzoj1449

    竞赛图一般是把每场比赛当作一个点,然后和相应球队连边每场比赛一赢一输对两支球队都有影响看起来不好搞实际上我们可以先假设参加后面后面所有球队都输(每场比赛双输)然后对每场比赛我们选择一支球队赢计算增加的 ...

  6. React入门1

    React教程 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <t ...

  7. HDU 5936 Difference 【中途相遇法】(2016年中国大学生程序设计竞赛(杭州))

    Difference Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  8. [转]NHibernate之旅(2):第一个NHibernate程序

    本节内容 开始使用NHibernate 1.获取NHibernate 2.建立数据库表 3.创建C#类库项目 4.设计Domain 4-1.设计持久化类 4-2.编写映射文件 5.数据访问层 5-1. ...

  9. 基于.NET平台常用的框架和开源程序整理

    自从学习.NET以来,优雅的编程风格,极度简单的可扩展性,足够强大开发工具,极小的学习曲线,让我对这个平台产生了浓厚的兴趣,在工作和学习中 也积累了一些开源的组件,就目前想到的先整理于此,如果再想到, ...

  10. Red5空项目的理解

    在经过三天的苦恼之后,我终于对Red5的工作流程有点了解了.这样一来对要做的项目总算不会太瞎了.出于个人感受,认为下面所讲述的内容对初学者理解Red5以及基于Red5开发有很大的帮助,因此记录下来. ...