Linux 下Nginx默认参数编译安装与启动配置
官网: www.nginx.org
版本: Stable version ==> nginx-1.14.0
编译:
命令: ./configure –prefix=/data/nginx
问题: the HTTP rewrite module requires the PCRE library …
处理: nginx 默认是开启 rewrite 功可以,此处需要 PCRE 库,或者者用命令关闭 rewrite
下载PCRE库,有两个版本,还有一个是PCRE2,我下载的是【pcre-8.42】,
假如用的是 pcre2 则,需要升级 perl 到 perl 5
关于configure 的说明,请参考:http://nginx.org/en/docs/configure.html
命令: ./configure –prefix=/data/nginx –with-pcre=/root/pcre-8.42
成功用Nginx默认的配置编译完成,注意以下参数的默认值:
–user # 运行的使用户,此使用户已存在
–group # 选择的使用户组,此组已存在
–error-log # 默认的错误日志
–pid-path # PID 文件
–conf-path # 全局配置文件
–lock-path # lock 文件
命令: make && make install
执行完成之后,可在安装目录看到如下目录结构,在运行Nginx会生成其它的缓存目录:
/data/nginx
├── conf # 所有配置文件目录,后缀为 default 的都是默认的配置文件,使用于复原配置用
│ ├── fastcgi.conf # fastcgi 配置文件
│ ├── fastcgi.conf.default
│ ├── fastcgi_params # fastcgi 参数
│ ├── fastcgi_params.default
│ ├── koi-utf # 未知
│ ├── koi-win # 未知
│ ├── mime.types # Http mime 类型
│ ├── mime.types.default
│ ├── nginx.conf # 全局配置文件,可使用 include 包含,比方: include ./vhost/*.conf
│ ├── nginx.conf.default
│ ├── scgi_params # scgi 参数
│ ├── scgi_params.default
│ ├── uwsgi_params # uwsgi 参数
│ ├── uwsgi_params.default
│ └── win-utf # 未知
├── html # Nginx 默认的网页,在编译安装完成并启动之后,默认就显示此目录下的内容
│ ├── 50x.html
│ └── index.html
├── logs # 日志目录
└── sbin # 可执行文件目录
└── nginx # Nginx启动程序
启动:
编辑安装的Nginx是没有提供启动脚本的,“【修改】”表示需要修改,
此脚本放到 /etc/init.d/ 目录下,并命令为 nginx 并增加执行权限 chmo +x nginx
脚本内容参考如下:
#!/bin/bash
# 此脚本需要,在编辑Nginx的时候,需要增加有 –user 参数,或者者在此脚本中关闭 “make_dirs” 函数的调使用
# 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: /usr/local/nginx/nginx.conf # 【修改】配置文件路径
# pidfile: /var/run/nginx.pid # 【修改】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/local/nginx/sbin/nginx” # 【修改】Nginx执行文件路径
prog=$(basename $nginx)
NGINX_CONF_FILE=”/usr/local/nginx/conf/nginx.conf” # 【修改】主配置文件
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
# 从编译命令中获取相关参数,并创立必要的目录与运行使用户,同时分配权限
make_dirs() {
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
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 # daemon 为 functions 中定义的函数,调使用它来启动
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 # 调使用 functions 中的函数,返回状态
}
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 增加到自启动服务器列表
chkconfig –level 2345 nginx on 系统在2345启动模式下自动启使用Nginx
chkconfig –list 查看
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是摆设,本站源码仅提供给会员学习使用!
7. 如遇到加密压缩包,请使用360解压,如遇到无法解压的请联系管理员
开心源码网 » Linux 下Nginx默认参数编译安装与启动配置