jackyrar 发表于 2018-11-12 08:32:52

编译安装nginx-1.9.12-whatyang

  编译定制安装nginx-1.9.12
  源码包nginx-1.9.12.tar.gz在www.nginx.org上获取。
  环境:CentOS release 6.2
  #tar xf nginx-1.9.12.tar.gz -C /usr/local/src #解压缩到此路径
  #cd /usr/local/src
  #ln -sv nginx-1.9.12 nginx #创建链接
  #cd /nginx
  #yum -y install pcre gcc* 安装编译需要的模块,一般gcc是必须的
  #groupadd nginx
  #useradd -r nginx -g nginx
  #./configure --help | less #可以查看编译时可添加的功能等
  #./configure \#\为换行符
  --prefix=/usr \ nginx #安装路径
  --sbin-path=/usr/bin/nginx#\命令路径
  --conf-path=/etc/nginx/nginx.conf \ #配置文件路径
  --error-log-path=/var/log/nginx/error.log \ #错误日志路径
  --http-log-path=/var/log/nginx/access.log \ #http访问日志路径
  --pid-path=/var/run/nginx/nginx.pid \ #nginx的pid文件路径
  --lock-path=/var/lock/nginx.lock \ #锁文件路径
  --user=nginx \ #运行nginx的用户
  --group=nginx \ #运行nginx的组
  --with-http_ssl_module \ #编译时安装http_ssl_module模块
  --with-http_flv_module \ #编译时安装http_flv_module模块
  --with-http_stub_status_module \ #安装http_stub_status_module
  --with-http_gzip_static_module\ #安装http_gzip_static_module
  --http-client-body-temp-path=/var/tmp/nginx/client/\
  #客户端请求临时目录
  --http-proxy-temp-path=/var/tmp/nginx/proxy/\
  #nginx做反向代理时临时目录
  --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/\
  #nginx与php交互临时目录
  --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
  #Python相关
  --http-scgi-temp-path=/var/tmp/nginx/scgi
  --with-pcre \
  编译过程如果报目录不存在的错误就去创建目录。
  #make && make install
  cp nginx/conf/nginx.conf /etc/nginx/nginx.conf #提供配置文件
  为nginx提供服务脚本
  vim /etc/rc.d/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/bin/nginx"
  prog=$(basename $nginx)
  NGINX_CONF_FILE="/etc/nginx/nginx.conf"
  [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
  lockfile=/var/lock/subsys/nginx
  start() {
  [ -x $nginx ] || exit 5
  [ -f $NGINX_CONF_FILE ] || exit 6
  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
  killall -9 nginx
  }
  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
  #chkconfig --add nginx #向服务里添加nginx
  #chkconfig nginx on #开机启动
  #service nginx start #启功nginx
  到此nginx编译完成。
  总结:编译出错时,我们要认真观察屏幕上报错的信息,一般都是缺少某个文件或者程序所依赖的库文件等等,通过报错信息定位缺少的东西,然后下载安装,缺什么就补什么,重新编译即可。

页: [1]
查看完整版本: 编译安装nginx-1.9.12-whatyang