nginx的编译安装

  

1,安装编译环境
<代码> yum - y安装gcc gcc-c + +使ncurses ncurses-devel

  

2,安装pcre软件包(使nginx支持http重写模块)
<代码> yum安装- y pcre pcre-devel

  

3,安装openssl-devel(使nginx支持ssl)
<代码> yum安装- y openssl openssl-devel

  

4,安装zlib
<代码> yum安装- y zlib zlib-devel

  

5,创建用户nginx

  
 <代码> groupadd nginx
  useradd - r - g nginx - s/sbin/nologin nginx  
  

6,安装nginx

  
 <代码> root@localhost ~ # wget http://nginx.org/download/nginx-1.16.0.tar.gz
  (root@localhost ~) #焦油xzf nginx-1.16.0.tar。广州- c/usr/local/(root@localhost ~) # cd/usr/local/nginx-1.16.0/ 
  
 <代码> [root@localhost nginx-1.16.0] # ./configure——prefix=/usr/本地/nginx——组=nginx——用户=nginx sbin-path=/usr/地方/nginx/sbin/nginx——conf-path=/etc/nginx/nginx。相依——error-log-path=/var/log/nginx/错误。日志——http-log-path=/var/log/nginx/访问。日志——http-client-body-temp-path=/tmp/nginx/client_body http-proxy-temp-path——http-fastcgi-temp-path==/tmp/nginx/代理/tmp/nginx/fastcgi——pid-path=/var/run/nginx。pid - lock-path=/var/锁定/nginx——with-http_stub_status_module with-http_ssl_module——with-http_gzip_static_module with-pcre——with-http_realip_module——与河流
  
  [root@localhost nginx-1.16.0] #做,,制作安装
  
  [root@localhost nginx-1.16.0] # cd/tmp/(root@dabing tmp) # mkdir nginx
  [root@dabing sbin] # cd/usr/local/nginx/sbin (/usr/地方/nginx/sbin/nginx开启nginx)
  (root@dabing sbin) #。/nginx
  [root@dabing sbin] #党卫军-antpl  
  

[root@dabing sbin] # vim/etc/init.d/nginx #开机自动开启脚本

  
 <代码> # !/bin/sh
  。/etc/rc.d/init.d/functions
  。/etc/sysconfig/network
  [" $网络”=安弧?,,退出0
  
  nginx="/usr/地方/nginx/sbin/nginx”
  学监=$ (basename nginx美元)
  
  NGINX_CONF_FILE="/etc/nginx/nginx.conf”
  
  (- f/etc/sysconfig/nginx),,。/etc/sysconfig/nginx
  
  lockfile=/var/锁定/nginx
  
  make_dirs () {
  用户=' nginx - v 2祝辞,1 | grep“配置参数:”| sed的s/*——用户=\ [^ *)(* \ [^])。*/\ 1/g”——“
  选择=' $ nginx - v 2祝辞,1 | grep的配置参数:“
  在美元选择选项;做
  如果(echo $选择| grep。* -temp-path ');然后
  价值=https://www.yisu.com/zixun/echo $选择|切- d”=? f 2
  如果[!- d“美元价值”);然后
  #回声”创造“美元价值
  mkdir - p美元价值,,乔恩- r用户价值的美元
  fi
  fi
  完成
  }
  
  start () {
  5 (- x nginx美元)| |退出
  [- f $ NGINX_CONF_FILE] | |退出6
  make_dirs
  echo - n”美元美元开始掠夺:“
  守护进程nginx - c NGINX_CONF_FILE美元
  retval=$ ?
  回声
  (美元retval eq 0],,触摸lockfile美元
  返回retval美元
  }
  
  stop () {
  echo - n”美元美元停止掠夺:“
  killproc美元掠夺辞职
  retval=$ ?
  回声
  (美元retval eq 0],,rm - f lockfile美元
  返回retval美元
  }
  
  重启(){
  configtest | |返回$ ?
  停止
  睡眠1
  开始
  }
  
  重载(){
  configtest | |返回$ ?
  echo - n $”重载美元掠夺:“
  美元killproc nginx玫瑰
  RETVAL=$ ?
  回声
  }
  
  force_reload () {
  重新启动
  }
  
  configtest () {
  nginx - t - c NGINX_CONF_FILE美元
  }
  
  rh_status () {
  美元地位的掠夺
  }
  
  rh_status_q () {
  rh_status在/dev/null 2祝辞,1
  }
  
  “1美元”
  开始)
  rh_status_q,,退出0
  1美元
  ;;
  停止)
  rh_status_q | 0 |退出
  1美元
  ;;
  重启| configtest)
  1美元
  ;;
  重新加载)
  rh_status_q | |退出7
  1美元
  ;;
  才)
  force_reload
  ;;
  状态)
  rh_status
  ;;
  condrestart | try-restart)
  rh_status_q | 0 |退出
  ;;
  *)
  echo $”用法:$ 0 |{开始停止状态| |重启| condrestart | try-restart |重载|才| configtest}”
  出口2
  esac  
  

[root@dabing sbin] # chmod + x/etc/init.d/nginx(实现nginx的开机自起)
[root@dabing sbin] # systemctl daemon-reload
[root@dabing sbin] # systemctl开始nginx
[root@dabing sbin] #/sbin/chkconfig nginx在
[root@dabing sbin] # systemctl地位nginx

nginx的编译安装