nginx 源码安装

2023-03-23  本文已影响0人  码农工号9527

下载

cd /data/downloads/
wget http://nginx.org/download/nginx-1.23.2.tar.gz

安装必要的库文件

yum install -y vim telnet lrzsz git make gcc screen sys stat dstat iotop iptraf unzip ncurses-devel vixie-cron crontabs libaio wget man perl-Time-HiRes make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel

添加用户,已添加可以跳过

useradd www

解压

tar -xf nginx-1.23.2.tar.gz && cd nginx-1.23.2/

预编译

./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module

--with-ipv6不需要显示添加,最新版的nginx编译不需要添加--with-ipv6命令,它默认已经自带ipv6模块

安装

make && make install

建软链

ln -s /usr/local/nginx/sbin/nginx /usr/bin

配置启动文件

vim /etc/init.d/nginx,写入内容

#!/bin/bash
#
# nginx - this script starts and stops the nginx daemin
#
# 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/conf/nginx.conf
# pidfile:     /usr/local/nginx/logs/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/local/nginx/sbin/nginx"
prog=$(basename $nginx)

NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"

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
}

restart() {
    configtest || return $?
    stop
    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

测试

[root@test conf]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@test conf]# /etc/init.d/nginx start
Reloading systemd:                                         [  OK  ]
Starting nginx (via systemctl):                            [  OK  ]
[root@test conf]# /etc/init.d/nginx status
● nginx.service - SYSV:  Nginx is an HTTP(S) server, HTTP(S) reverse               proxy and IMAP/POP3 proxy server
   Loaded: loaded (/etc/rc.d/init.d/nginx; bad; vendor preset: disabled)
   Active: active (running) since Fri 2023-03-24 12:04:44 CST; 4s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 11686 ExecStart=/etc/rc.d/init.d/nginx start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/nginx.service
           ├─11699 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
           └─11700 nginx: worker process

Mar 24 12:04:44 huoyu-dev-oversea systemd[1]: Starting SYSV:  Nginx is an HTTP(S) server, HTTP(S) reverse               proxy and IMAP/POP3 proxy server...
Mar 24 12:04:44 huoyu-dev-oversea nginx[11686]: Starting nginx: [  OK  ]
Mar 24 12:04:44 huoyu-dev-oversea systemd[1]: Started SYSV:  Nginx is an HTTP(S) server, HTTP(S) reverse               proxy and IMAP/POP3 proxy server.
上一篇 下一篇

猜你喜欢

热点阅读