koflover 发表于 2018-11-13 09:31:34

源码配置nginx

# yum remove httpd  
# setenforce 0       //尽量关闭防火墙和SELinux
  
# tar -zxvf nginx-1.4.4.tar.gz -C /usr/local/src/nginx-1.4.4/
  
# ./configure \
  
--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/nginx.pid \
  
--lock-path=/var/lock/nginx.lock \
  
--user=nginx \
  
--group=nginx \
  
--with-http_ssl_module \
  
--with-http_flv_module \
  
--with-http_stub_status_module \
  
--with-http_gzip_static_module \
  
--http-client-body-temp-path=/var/tmp/nginx/client/ \
  
--http-proxy-temp-path=/var/tmp/nginx/proxy/ \
  
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
  
--with-pcre
  
//路径详单
  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx configuration prefix: "/etc/nginx"
  nginx configuration file: "/etc/nginx/nginx.conf"
  nginx pid file: "/var/run/nginx/nginx.pid"
  nginx error log file: "/var/log/nginx/error.log"
  nginx http access log file: "/var/log/nginx/access.log"
  nginx http client request body temporary files: "/var/tmp/nginx/client/"
  nginx http proxy temporary files: "/var/tmp/nginx/proxy/"
  nginx http fastcgi temporary files: "/var/tmp/nginx/fcgi/"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"
  
# make && make install
  
# cd /etc/nginx/sbin/
  
# ./nginx -h             //显示帮助
  
nginx version: nginx/1.4.4
  
Usage: nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]
  
Options:
  -?,-h         : this help
  -v            : show version and exit
  -V            : show version and configure options then exit
  -t            : test configuration and exit
  -q            : suppress non-error messages during configuration testing

  -s signal   : send signal to a master process: stop, quit, reopen,>  -p prefix   : set prefix path (default: /usr/local/nginx/)
  -c filename   : set configuration file (default: /etc/nginx/nginx.conf)
  -g directives : set global directives out of configuration file
  
# ./nginx -v            //显示版本
  
nginx version: nginx/1.4.4
  
# ./nginx -t            //测试语法,有错误
  
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
  
nginx: mkdir() "/var/tmp/nginx/client/" failed (2: No such file or directory)
  
nginx: configuration file /etc/nginx/nginx.conf test failed
  
# mkdir -pv /var/tmp/nginx/client    //按照提示更正错误
  
mkdir: created directory `/var/tmp/nginx'
  
mkdir: created directory `/var/tmp/nginx/client'
  
# ./nginx -t
  
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
  
nginx: configuration file /etc/nginx/nginx.conf test is successful
  
# ./nginx               //启动nginx
  
# netstat -tupln |grep nginx
  
tcp      0      0 0.0.0.0:80   0.0.0.0:*    LISTEN      12682/nginx
  
# vim /etc/init.d/nginx    //编辑nginx启动脚本
  
#!/bin/bash
  
. /etc/init.d/functions
  
prog=/usr/local/nginx/sbin/nginx
  
lockfile=/var/lock/nginx.lock
  
start   (){
  if [ -e $lockfile ];then
  echo "nginx is started" && exit
  else
  echo-n "nginx is starting....."
  sleep 1
  $prog &>/dev/null&& touch $lockfile &&echo "OK" || echo "failer"
  fi
  
}
  
configtest (){
  $prog -t
  
}
  
stop    (){
  if [ ! -e $lockfile ];then
  echo "nginx is stoped" && exit
  else
  echo -n "httpd is stoping......"
  sleep 1
  $prog -s stop &>/dev/null&& rm -rf $lockfile &&echo "OK"|| echo "failer"
  fi
  
}
  
restart() {
  if [ -e $lockfile ];then
  
killprocnginx && rm -rf $lockfile
  else
  $prog && echo "OK" && touch $lockfile
  fi
  
}
  
case "$1" in
  
start)
  start
  ;;
  
stop)
  stop
  ;;
  
restart)
  restart
  ;;
  
configtest)
  configtest
  ;;
  
*)      echo "Usage:start|stop|configtest|restart"
  
esac
  
# chmod a+x /etc/init.d/nginx
  
# vim/etc/nginx/nginx.conf       //nginx主配置文档
  12 events {
  13   use epoll;               //使用epoll机制
  14   worker_connections1024;
  15 }
  
# service nginx restart


页: [1]
查看完整版本: 源码配置nginx