Get the App
SLTechnology News&Howtos  ›  Servers  › 

Compilation and installation of nginx

Shulou Source: shulou.com Published: 2022-06-02 13:18:24 11月14日 Update

1. Install the compilation environment

Yum-y install gcc gcc-c++ make ncurses ncurses-devel

2. Install pcre software package (make nginx support http rewrite module)

Yum install-y pcre pcre-devel

3. Install openssl-devel (make nginx support ssl)

Yum install-y openssl openssl-devel

4. Install zlib

Yum install-y zlib zlib-devel

5. Create a user nginx

Groupadd nginxuseradd-r-g nginx-s / sbin/nologin nginx

6. Install nginx

[root@localhost ~] # wget http://nginx.org/download/nginx-1.16.0.tar.gz[root@localhost ~] # tar xzf nginx-1.16.0.tar.gz-C / usr/local/ [root@localhost ~] # cd / usr/local/nginx-1.16.0/ [root@localhost nginx-1.16.0] #. / configure-- prefix=/usr/local/nginx-- group=nginx-- user=nginx-- sbin-path=/usr/local/nginx / sbin/nginx-conf-path=/etc/nginx/nginx.conf-error-log-path=/var/log/nginx/error.log-http-log-path=/var/log/nginx/access.log-http-client-body-temp-path=/tmp/nginx/client_body-http-proxy-temp-path=/tmp/nginx/proxy-http-fastcgi-temp-path=/tmp/nginx/fastcgi-pid-path=/var/run/nginx.pid-lock-path=/var / lock/nginx-with-http_stub_status_module-with-http_ssl_module-with-http_gzip_static_module-with-pcre-with-http_realip_module-with-stream [root@localhost nginx-1.16.0] # make & & make install [root@localhost nginx-1.16.0] # cd / tmp/ [root@dabing tmp] # mkdir nginx [root@dabing sbin] # cd / usr/local/nginx/sbin (/ Usr/local/nginx/sbin/nginx enables nginx) [root@dabing sbin] #. / nginx [root@dabing sbin] # ss-antpl

[root@dabing sbin] # vim / etc/init.d/nginx # Boot Auto start script

#! / bin/sh. / etc/rc.d/init.d/functions. / etc/sysconfig/network ["$NETWORKING" = "no"] & & exit 0 nginx= "/ usr/local/nginx/sbin/nginx" prog=$ (basename $nginx) NGINX_CONF_FILE= "/ etc/nginx/nginx.conf" [- f / etc/sysconfig/nginx] & &. / etc/sysconfig/nginxlockfile=/var/lock/nginxmake_dirs () {user= `nginx-V 2 > & 1 | grep "configure arguments:" | sed's / [^ *] *-- user=\ ([^] *\). * /\ 1configure arguments:' g'- `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

[root@dabing sbin] # chmod + x / etc/init.d/nginx (realize the boot of nginx)

[root@dabing sbin] # systemctl daemon-reload

[root@dabing sbin] # systemctl start nginx

[root@dabing sbin] # / sbin/chkconfig nginx on

[root@dabing sbin] # systemctl status nginx

Tags: Support compilation modules environment users scripts software software packages Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple OPPO Reno NVidia Redmi Linux