安装参数说明:
./configure #安装路径,但是对于Nginx来说这里也是默认页面存放路径 --prefix=/usr/nginx #nginx这个二进制程序放在那里 --sbin-path=建议放在/usr/sbin/nginx #配置文件存位置,实际上nginx还有其他配置文件,其他的不用指定位置,nginx.conf放那里他们 #就放那里 --conf-path=建议放在/etc/nginx/nginx.conf #错误日志存放位置 --error-log-path=建议放在/var/log/nginx/error.log #HTTP访问日志存放位置 --http-log-path=建议放在/var/log/nginx/access.log #PID文件路径 --pid-path=建议放在/var/run/nginx/nginx.pid #锁文件路径 --lock-path=/var/lock/nginx.lock #属组和属主,前提是你得建立这个组和账号,如果不指定,默认都是nobody --user=nginx --group=nginx #启用哪些Nginx自带的功能模块 --with-file-aio --with-threads --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_geoip_module --with-http_realip_module --with-http_v2_module --with-http_realip_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/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi/ --http-scgi-temp-path=/var/tmp/nginx/scgi/ #额外添加的第三方模块,= 后面指定的是这些模块解压后的路径 --add-module=/opt/ngx_cache_purge-2.3 用于做加速 --add-module=/opt/ngx_http_lower_upper_case-master 用于大小写转换 --add-module=/opt/headers-more-nginx-module-0.32 用于添加、设置和清除输入、输出头信息 #设置的其他路径 #主体临时目录,处理HTTP请求时,如果包体需要暂时存放在磁盘中 --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/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi/ --http-scgi-temp-path=/var/tmp/nginx/scgi/ --with-openssl=/PATH openssl源码解压路径,这个的作用是指定Nginx的SSL模块依赖的SSL库 --with-http_ssl_module表示启用SSL模块 --with-pcre=/PATH pcre源码包解压路径,无需安装 --with-zlib=/PATH zlib源码包解压路径,无需安装 #第三方模块查询 #https://www.nginx.com/resources/wiki/modules/
安装演示:
我这里下载的依赖的库和第三方模块都放在了/usr/local/src中
首先创建用户和组
创建/var/tmp下的nginx目录
至于其他目录,都会自动创建,如下图
如果想把这个过程保存一下就这样写,tee过去,不能用输出重定向,因为如果用了当前你就看不到了。
安装完成后查看一下nginx程序的帮助,可以看到:
-s是给Master进程发信号,停止、(reload)重新加载配置文件,对当前用户没影响对后续用户有影响、重新打开
-t测试主配置文件是否有语法错误
测试一下配置文件
如果报错,如下,说明你的nginx用户和组没有创建
启动Nginx
查看进程,可以看到目前启动时一个Master和一个Work,而且Work是以nginx用户启动的。而master也就是主进程是root用户运行的。
它的默认页面文件存放位置在/usr/nginx下面,这个就是Nginx的安装路径,html这个目录安装的时候也无法设置,只能安装完以后从配置文件中修改
配置自动启动和称为系统服务
这个需要建立一个脚本,并放到/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 # 在/etc/init.d/下面建立nginx执行脚本,复制下面的内容,然后chmod +x 权限 # chkconfig --level 3 nginx on # 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:" | sed ‘s/[^*]*--user=\([^ ]*\).*/\1/g‘ -` 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 } 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
我常用的安装参数:
./configure --prefix=/usr/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/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-file-aio --with-threads --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_geoip_module --with-http_v2_module --with-http_realip_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/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi/ --http-scgi-temp-path=/var/tmp/nginx/scgi/ --add-module=/usr/local/src/headers-more-nginx-module-0.32 --add-module=/usr/local/src/ngx_cache_purge-2.3 --add-module=/usr/local/src/ngx_http_lower_upper_case-master --add-module=/usr/local/src/nginx_upstream_check_module-master --add-module=/usr/local/src/nginx-upstream-fair-master --with-openssl=/usr/local/src/openssl-1.1.0c --with-zlib=/usr/local/src/zlib-1.2.11 --with-pcre=/usr/local/src/pcre-8.39
本文出自 “小恶魔的家” 博客,请务必保留此出处http://littledevil.blog.51cto.com/9445436/1901387
原文:http://littledevil.blog.51cto.com/9445436/1901387