Linux下安装Nginx

  • 准备工作
    • SSL功能需要openssl库,下载地址https://www.openssl.org/source/openssl-1.0.2n.tar.gz
    • gzip模块需要zlib库,下载地址http://www.zlib.net/zlib-1.2.11.tar.gz
    • rewrite模块需要pcre库,下载地址https://ftp.pcre.org/pub/pcre/pcre-8.41.tar.gz
  • 通过wget下载到软件安装目录
    • wget https://www.openssl.org/source/openssl-1.0.2n.tar.gz
    • wget http://www.zlib.net/zlib-1.2.11.tar.gz
    • wget https://ftp.pcre.org/pub/pcre/pcre-8.41.tar.gz
  • 依赖库安装
    • yum install perl
    • yum install gcc
    • yum install gcc-c++
  • 编译安装openssl
    • tar zxvf soft/openssl-1.0.2n.tar.gz
    • cd openssl-1.0.2n
    • ./config
    • make
    • make install
  • 编译安装zlib
    • tar zxvf sotf/zlib-1.2.11.tar.gz
    • cd zlib-1.2.11
    • ./configure
    • make
    • make install
  • 编译安装pcre
    • tar zxvf soft/pcre-8.41.tar.gz 
    • cd cd pcre-8.41
    •  ./configure 
    • make
    • make install
  • 也可以yum安装依赖
    •    yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
  • 获取Nginx
    • wget http://nginx.org/download/nginx-1.13.8.tar.gz
  • 编译安装Nginx
    • tar zxvf soft/nginx-1.13.8.tar.gz 
    • cd nginx-1.13.8/
    •  ./configure --with-pcre=../pcre-8.41/ --with-zlib=../zlib-1.2.11/ --with-openssl=../openssl-1.0.2n/
    • make
    • make install
    • 安装目录默认为/usr/local/nginx
  • 验证安装
    • /usr/local/nginx/sbin/nginx -t
    • nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
      nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

  • 开机启动配置
    •   
      #!/bin/sh 
      # chkconfig: 2345 85 15 
      # Startup script for the nginx Web Server 
      # description: nginx is a World Wide Web server.  
      # It is used to serve HTML files and CGI. 
      # processname: nginx 
      # pidfile: /usr/local/nginx/logs/nginx.pid 
      # config: /usr/local/nginx/conf/nginx.conf 
         
      PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 
      DESC="nginx deamon" 
      NAME=nginx 
      DAEMON=/usr/local/nginx/sbin/$NAME 
      SCRIPTNAME=/etc/init.d/$NAME 
         
      test -x $DAEMON || exit 0 
         
      d_start(){ 
        $DAEMON || echo -n "already running" 
      } 
         
      d_stop(){ 
        $DAEMON -s quit || echo -n "not running" 
      } 
         
         
      d_reload(){ 
        $DAEMON -s reload || echo -n "can not reload" 
      } 
         
      case "$1" in 
      start) 
        echo -n "Starting $DESC: $NAME" 
        d_start 
        echo "." 
      ;; 
      stop) 
        echo -n "Stopping $DESC: $NAME" 
        d_stop 
        echo "." 
      ;; 
      reload) 
        echo -n "Reloading $DESC conf..." 
        d_reload 
        echo "reload ." 
      ;; 
      restart) 
        echo -n "Restarting $DESC: $NAME" 
        d_stop 
        sleep 2 
        d_start 
        echo "." 
      ;; 
      *) 
        echo "Usage: $ScRIPTNAME {start|stop|reload|restart}" >&2 
        exit 3 
      ;; 
      esac 
         
      exit 0 
      chmod +x /etc/init.d/nginx 
      chkconfig --add nginx 
      chkconfig nginx on/off 
      chkconfig --list nginx 
 
原文地址:https://www.cnblogs.com/growingpains/p/8250538.html