Install nginx on centos7 system and configure the startup operation
- 2020-05-13 04:28:31
- OfStack
The preparatory work
My centos7 system is minimally installed and lacks a lot of libraries. First, install the necessary runtime libraries
yum install wget gcc gcc-c++ pcre-devel zlib-devel
## Create the working directory and enter the working directory
mkdir -p /z/nginx && cd /z/nginx
## To obtain nginx Latest installation package
wget http://nginx.org/download/nginx-1.11.10.tar.gz
## unzip
tar zxvf nginx-1.11.10.tar.gz
## Enter the directory
cd nginx-1.11.10
## Detection system configuration , generate make The relevant documents
./configure
Successful execution of./configure outputs the following information
Where nginx is installed, and the file path
Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
+ using system zlib library
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
Compile and install
make && make install
Create the nginx launch command script
vi /etc/init.d/nginx
Insert the following and be careful to modify the PATH and NAME fields to match your own installation path (this is from copy on the web)
#! /bin/bash
# chkconfig: - 85 15
PATH=/usr/local/nginx
DESC="nginx daemon"
NAME=nginx
DAEMON=$PATH/sbin/$NAME
CONFIGFILE=$PATH/conf/$NAME.conf
PIDFILE=$PATH/logs/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
set -e
[ -x "$DAEMON" ] || exit 0
do_start() {
$DAEMON -c $CONFIGFILE || echo -n "nginx already running"
}
do_stop() {
$DAEMON -s stop || echo -n "nginx not running"
}
do_reload() {
$DAEMON -s reload || echo -n "nginx can't reload"
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
do_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
do_stop
echo "."
;;
reload|graceful)
echo -n "Reloading $DESC configuration..."
do_reload
echo "."
;;
restart)
echo -n "Restarting $DESC: $NAME"
do_stop
do_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
exit 3
;;
esac
exit 0
Set execution permissions
chmod a+x /etc/init.d/nginx
Register as service
chkconfig --add nginx
Set to boot
chkconfig nginx on
Restart to see if the nginx service starts automatically
shutdown -h 0 -r
netstat -apn|grep nginx
Perform stop/start/re-read configuration file operations on the nginx service
# Start the nginx service
systemctl start nginx.service
# stop nginx service
systemctl stop nginx.service
# restart nginx service
systemctl restart nginx.service
# reread nginx configuration ( This is the most commonly used , Don't stop nginx The service enables the modified configuration to take effect )
systemctl reload nginx.service