此文章是接上篇文章“源码包安装LNMP之MYSQL”来写的
1.创建运行nginx服务的用户
[root@localhost ~]# useradd -s /sbin/nologin -M nginxginx
2.解压pcre
[root@localhost src]# tar -zxvf pcre-8.41.tar.gz
3.配置pcre
[root@localhost pcre-8.41]# ./configure
4.编译并安装pcre
[root@localhost pcre-8.41]# make && make install
5查看pcre版本
[root@localhost pcre-8.41]# pcre-config --version
8.41
6.安装nginx依赖包(Nginx依赖于pcre、zlib、openssl,在编译前配置时如果有问题
可以使用yum方式安装三个包pcre-devel、zlib-devel、openssl-devel)
[root@localhost src]# yum install -y pcre-devel zlib-devel openssl-devel
7.解压nginx
[root@localhost src]# tar -zxvf nginx-1.14.1.tar.gz
8.配置nginx编译环境
[root@localhost src]# cd nginx-1.14.1/
[root@localhost nginx-1.14.1]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module
编译环境配置完成如下图所示
9.编译安装nginx
[root@localhost nginx-1.14.1]# make&&make install
编译安装完成如下图所示
10.修改nginx安装目录权限所有者
[root@localhost local]# chown -R nginx:nginx /usr/local/nginx/
11.查看nginx安装目录结构
[root@localhost src]# cd nginx-1.14.1/
[root@localhost nginx-1.14.1]# cd /usr/local/nginx/
[root@localhost nginx]# tree
如下图所示
12.编辑nginx服务配置文件/usr/local/nginx/conf/nginx.conf ,修改nginx服务启动的默认用户为nginx
[root@localhost nginx]# vi /usr/local/nginx/conf/nginx.conf
#user nobody;
user nginx nginx;
worker_processes 1;
13.启动nginx
[root@localhost nginx]# /usr/local/nginx/sbin/nginx
14.查看nginx是否启动成功
[root@localhost nginx]# ps aux|grep nginx
15.查看nginx端口占用情况
[root@localhost nginx]# netstat -tlnp|grep nginx
16.防火墙放行80端口
[root@localhost nginx]# firewall-cmd --permanent --add-port=80/tcp
success
[root@localhost nginx]# firewall-cmd --reload
success
17.客户端浏览器访问服务器地址出现下图所示,表示己经安装成功了
18.将nginx命令添加到环境变量,修改/etc/profile文件
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib:/usr/local/nginx/sbin
更新配置文件:source /etc/profile
19.通过命令关闭 启动nginx
a.启动nginx服务
b.立刻停止nginx服务:
[root@localhost nginx]# nginx -s stop
c.完成当前任务后停止nginx服务
[root@localhost nginx]# nginx -s quitt
20.把nginx
命令添加到系统服务
创建并编辑文件/etc/rc.d/init.d/nginx
[root@localhost nginx]# vim /etc/rc.d/init.d/nginx
#!/bin/bash
# nginx - this script starts and stops the nginx daemon
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /usr/local/nginx/logs/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 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
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
}
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
20.保存脚本并增加执行权限
[root@localhost nginx]# vim /etc/rc.d/init.d/nginx
[root@localhost nginx]# chmod 755 /etc/rc.d/init.d/nginx
21.通过系统服务命令管理nginx服务
[root@localhost nginx]# systemctl restart nginx
至此nginx的源码包安装就安装完毕了,PHP的源码包安装会在下一篇文章里讲到
原文地址:https://www.cnblogs.com/happysnowy/p/13211552.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。