nginx1.8.1编译安装

nginx


Nginx is a free, open-source, high-performance HTTP server and reverse proxy, as well as an IMAP/POP3 proxy server. Igor Sysoev started development of Nginx in 2002, with the first public release in 2004. Nginx now hosts nearly 7.67% (35.5M) of all domains worldwide.


Nginx is known for its high performance, stability, rich feature set, simple configuration, and low resource consumption.


Nginx is one of a handful of servers written to address the C10K problem. Unlike traditional servers, Nginx doesn't rely on threads to handle requests. Instead it uses a much more scalable event-driven (asynchronous) architecture. This architecture uses small, but more importantly, predictable amounts of memory under load.
Even if you don't expect to handle thousands of simultaneous requests, you can still benefit from Nginx's high-performance and small memory footprint. Nginx scales in all directions: from the smallest VPS all the way up to clusters of servers.


Nginx powers several high-visibility sites, such as WordPress, Hulu, Github, Ohloh, SourceForge, WhitePages and TorrentReactor.


一、安装nginx时必须先安装相应的编译工具
yum -y install gcc gcc-c++ autoconf automake
yum -y install zlib zlib-devel mod_ssl openssl openssl-devel pcre-devel


建立nginx 组
groupadd -r nginx
useradd -g nginx -M -s /sbin/nologin -r nginx
id nginx


zlib:nginx提供gzip模块,需要zlib库支持
openssl:nginx提供ssl功能
pcre:支持地址重写rewrite功能


二、下载安装包并解压


wget http://nginx.org/download/nginx-1.8.1.tar.gz


tar -zxvf nginx-1.8.1.tar.gz


三、编译安装
cd nginx-1.8.1


./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-threads


四、make && make install


五、nginx启动脚本


官方文档:http://wiki.nginx.org/RedHatNginxInitScript


Should work on RHEL, Fedora, CentOS. Tested on CentOS 5.


Save this file as /etc/init.d/nginx


#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig:   - 85 15
# 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 0


nginx="/usr/sbin/nginx"
prog=$(basename $nginx)


NGINX_CONF_FILE="/etc/nginx/nginx.conf"


[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx


lockfile=/var/lock/subsys/nginx


make_dirs() {
   # make required directories
   user=`$nginx -V 2>&1 | grep "configure arguments:.*--user=" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
   if [ -n "$user" ]; then
      if [ -z "`grep $user /etc/passwd`" ]; then
         useradd -M -s /bin/nologin $user
      fi
      options=`$nginx -V 2>&1 | grep 'configure arguments:'`
      for opt in $options; do
          if [ `echo $opt | grep '.*-temp-path'` ]; then
              value=`echo $opt | cut -d "=" -f 2`
              if [ ! -d "$value" ]; then
                  # echo "creating" $value
                  mkdir -p $value && chown -R $user $value
              fi
          fi
       done
    fi
}


start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    make_dirs
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}


stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}


restart() {
    configtest || return $?
    stop
    sleep 1
    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 2>&1
}


case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
            ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
esac




chmod +x  /etc/init.d/nginx   ###给/etc/init.d/nginx执行权限


六、启动nginx


service nginx start
Starting nginx (via systemctl):                            [  确定  ]


service nginx status
● nginx.service - SYSV: NGINX is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server
   Loaded: loaded (/etc/rc.d/init.d/nginx; bad; vendor preset: disabled)
   Active: active (running) since 六 2017-02-18 22:33:36 CST; 3min 50s ago
     Docs: man:systemd-sysv-generator(8)
 Main PID: 16029 (nginx)
   CGroup: /system.slice/nginx.service
           ├─16029 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
           └─16031 nginx: worker process


2月 18 22:33:36 nginx2 systemd[1]: Starting SYSV: NGINX is an HTTP(S) server, HTTP(S) reverse pro...r...
2月 18 22:33:36 nginx2 nginx[15909]: Starting nginx: [  确定  ]
2月 18 22:33:36 nginx2 systemd[1]: PID file /var/run/nginx.pid not readable (yet?) after start.
2月 18 22:33:36 nginx2 systemd[1]: Started SYSV: NGINX is an HTTP(S) server, HTTP(S) reverse prox...ver.
Hint: Some lines were ellipsized, use -l to show in full.


开机启动nginx
chkconfig  nginx on 


systemctl stop firewalld
systemctl disable firewalld
setenforce 0
vim /etc/selinux/config 
SELINUX=disabled


登陆页面
Welcome to nginx!


If you see this page, the nginx web server is successfully installed and working. Further configuration is required.


For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.


Thank you for using nginx.


nginx安装完成


  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值