安装包准备:
安装包已上传百度云,其中nginx版本客根据需要去官方重新下载
链接:https://pan.baidu.com/s/1qAuTjTK9f6Il2Lp6shQsPQ?pwd=ggj2
提取码:ggj2
nginx1.22:
链接:https://pan.baidu.com/s/1T0B7a_SVaq0ETnJFtns77g?pwd=l35t
提取码:l35t
上传安装包到linux系统
一、进入gcc目录,执行以下命令
rpm -Uvh *.rpm --nodeps --force
gcc -v查看版本
二、 进入gcc-c++目录,执行命令
rpm -Uvh *.rpm --nodeps --force
g++ -v查看版本
三、安装PCRE
解压: tar -zxvf pcre-8.35.tar.gz
进入解压后的目录 cd pcre-8.35
依次执行以下命令
./configure
make
make install
四、安装libtool
解压: tar -zxvf libtool-2.4.2.tar.gz
进入解压后的目录 cd libtool-2.4.2
依次执行以下命令
./configure
make
make install
五、安装nginx
1、解压: tar -zxvf nginx-1.22.1.tar.gz
进入解压后的目录 cd nginx-1.22.1
依次执行以下命令
./configure
make
make install
nginx安装好的默认目录为/usr/local/nginx
2、启动nginx
cd /usr/local/nginx/sbin
./nginx
默认端口为80,浏览器直接访问ip即可
3、修改端口为8080
配置文件路径:
vim /usr/local/nginx/conf/nginx.conf
重新加载配置文件:
/usr/local/nginx/sbin/nginx -s reload
4、制作成服务,设置开机自启
vim /etc/init.d/nginx
内容:
#!/bin/bash
# chkconfig: 2345 85 15
# description: nginx Startup script for the Nginx HTTP Server
# processname: nginx
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/var/run/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
# reload nginx service functions.
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL
添加可执行权限,
chmod +x /etc/init.d/nginx
测试:
[root@fault121 conf]# cd /etc/init.d/
[root@fault121 init.d]# ls
functions netconsole network nginx README
[root@fault121 init.d]# ./nginx reload
./nginx: line 26: [: =: unary operator expected
Reloading nginx: [ OK ]
[root@fault121 init.d]# ./nginx stop
./nginx: line 26: [: =: unary operator expected
Stopping nginx: [ OK ]
[root@fault121 init.d]# ./nginx start
./nginx: line 26: [: =: unary operator expected
Starting nginx: [ OK ]
[root@fault121 init.d]#
开机自启动:
cd /etc/init.d
chkconfig nginx on
[root@fault122 init.d]# chkconfig nginx on
[root@fault122 init.d]# service nginx start
Starting nginx (via systemctl): [ OK ]
[root@fault122 init.d]# service nginx stop
Stopping nginx (via systemctl): [ OK ]
[root@fault122 init.d]# chkconfig --list
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off
redis 0:off 1:off 2:on 3:on 4:on 5:on 6:off