Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to source install Nginx automatic installation script and adapt to CentOS6

Shulou Source: shulou.com Published: 2022-06-01 03:11:09 10月17日 Update

This article shows you how to install the source code Nginx automatic installation script and adapt to CentOS6, the content is concise and easy to understand, absolutely can make your eyes bright, through the detailed introduction of this article, I hope you can get something.

On the operating system of CentOS6 series, download Nginx source code automatically through script, configure and install Nginx service, and finally add nginx to system service. You can operate nginx server through commands such as "service nginx start".

Nginx installation script (install-nginx.sh):

#! / bin/bash# installation configurationNGINX_VERSION=1.12.2NGINX_SRC_PATH=/rootNGINX_BIN_PATH=/usr/local/nginx# disable firewallservice iptables stopsetenforce installation dependenceyum install-y pcre-devel zlib-devel openssl-devel# download nginx source packagecd ${NGINX_SRC_PATH} wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz# unzip source packagetar-xzvf nginx-$ {NGINX_VERSION} .tar.gzcd. / nginx-$ {NGINX_VERSION} # install nginx. / configure-- prefix=$ {NGINX_BIN_PATH}-- with-http_ssl_modulemake & make install# add nginx to system serviceln-s ${NGINX_BIN_PATH} / sbin/nginx / usr/sbin/nginxcd ${NGINX_BIN_PATH} wget http://download.cloudhosts.xyz/linux/nginx/config/service-nginx # if this file cannot be downloaded Please replace mv service-nginx / etc/init.d/nginxcd / etc/init.d/chmod 755 nginx# test nginx serviceservice nginx restart with the service-nginx.sh file below

Add Nginx to system Services (service-nginx.sh):

This file is it (http://download.cloudhosts.xyz/linux/nginx/config/service-nginx)

#! / bin/sh## nginx-this script starts and stops the nginx daemon## chkconfig:-85 "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# Source function library.. / etc/rc.d/init.d/functions# Source networking configuration.. / etc/sysconfig/network# Check that networking is up. ["$NETWORKING" = "no"] & & exit 0nginx = "/ usr/sbin/nginx" prog=$ (basename $nginx) NGINX_CONF_FILE= "/ etc/nginx/nginx.conf" [- f / etc/sysconfig/nginx] & &. / etc/sysconfig/nginxlockfile=/var/lock/subsys/nginxmake_dirs () {# make required directories user= `$nginx-V 2 > & 1 | grep "configure arguments:.*--user=" | sed's / [^ *] *-user=\ ([^] *\). * /\ 1user= g'- `if [- n "$user"]; then 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 fi} 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 2esac the above is how to install the Nginx automatic installation script with source code and adapt to CentOS6. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Tags: Scripts services source code files systems adaptations content that is skills knowledge concise operating systems concise below commands articles more servers articles industry Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple MariaDB Shulou Information Linux vpn