Table of contents
1. Prepare nginx and dependent environment packages.
1. Upload the installation package to /usr/local/nginx.
4. To install pcre, unzip it first (pcre-8.35.tar.gz) and then install it.
8. Register nginx as a service.
2) Add a service and authorize the execution permission to the script
4) Service start | stop | restart command
1. Prepare nginx and dependent environment packages.
Link: https://pan.baidu.com/s/1UbL-wT2mob4bRPiBkw6JZA?pwd=9999
Extraction code: 9999
Baidu Netdisk can extract it by itself.
Second, install nginx.
1. Upload the installation package to /usr/local/nginx.
2. Install gcc
cd /usr/local/nginx/gcc
rpm -Uvh *.rpm --nodeps --force
Check if gcc is installed successfully
gcc -v
As shown in the figure above, it means the installation is successful!
3. Install g++
Switch directory, execute command to install rpm package
cd /usr/local/nginx/gcc-c++/
rpm -Uvh *.rpm --nodeps --force
The installation is completed as shown in the figure above.
Detect g++ version.
g++ -v
You can see the version number on the last line.
4. To install pcre, unzip it first (pcre-8.35.tar.gz) and then install it.
Switch directory to nginx
cd ..
Unzip the compressed package
tar -zxvf pcre-8.35.tar.gz
start installation
cd pcre-8.35
./configure
make
make install
5. Install libtool
switch directory
cd /usr/local/nginx/
unpack libtool-2.4.2.tar.gz
tar -zxvf libtool-2.4.2.tar.gz
cd libtool-2.4.2/
./configure
make
make install
6. Install nginx.
switch directory
cd /usr/local/nginx/
unzip nginx
tar -zxvf nginx-1.14.0.tar.gz
cd nginx-1.14.0/
./configure
The above command is the default, the following is with parameters
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
Note: configure, this step is generally used to generate Makefile to prepare for the next compilation, you can control the installation by adding parameters after configure.
make
make install
7. Start the nginx service.
nginx 安装目录地址 -c nginx配置文件地址
Note: If you install it according to my method, you will see the following directory
You will see that there are several more directories under /usr/local/nginx.
In fact, the directory where nginx is installed by default is /usr/local/nginx
Order | Operation content |
---|---|
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf | start nginx |
/usr/local/nginx/sbin/nginx -s stop (quit) | stop nginx |
/usr/local/nginx/sbin/nginx -s reload | restart nginx |
netstat -tunlp | View port usage |
netstat -tunlp | grep |
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
curl http://127.0.0.1:80
Seeing the above output, it means that nginx has started successfully!
8. Register nginx as a service.
1) Create a service script
vim /etc/init.d/nginx
The script content is as follows:
#! /bin/sh
# chkconfig: - 85 15
PATH=/usr/local/nginx/sbin
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/$NAME.conf
PIDFILE=/usr/local/nginx/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
2) Add a service and authorize the execution permission to the script
sudo chkconfig --add nginx
sudo chmod a+x /etc/init.d/nginx
3) Add boot self-start
chkconfig nginx on
4) Service start | stop | restart command
Start nginx:
service nginx start
Stop nginx:
service nginx stop
Restart nginx:
service nginx restart
After modifying the configuration file, reload the nginx service
service nginx reload
At this point, our nginx offline installation is complete.
If you have any questions, please give me your advice. I am a main backend Java programmer who is dedicated to full-stack development. In addition, if you have guitar or folk music lovers, you can follow my WeChat public account @民音吟家, and you can search on WeChat: Folk Musician, click a free follower for me, I am a person who loves life, loves code, and loves Passionate young people who make friends, I hope we can make progress and grow together.