linux服务器启动参数怎么配置,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 查看

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值