1. 安装Nginx
2. 通过命令解压
tar -zxvf nginx-1.18.0.tar.gz
3. 进行Nginx配置
找到目录下的 Configure 文件,进行配置
./configure --with-http_ssl_module
如果报错则运行一下命令
yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++

如果报错说明没有安装第三方的安装包。通过yum安装(联网的情况)第三方包。离线情况,自行百度二进制包安装方法。主要为三个依赖库 zlib,pcre,openssl。
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel

再执行 上面 configure 的命令进行配置。如图配置成功。
输入 make 命令 进行编译。
输入make install 进行插入。最后没有指定安装目录,则路径为 usr/local/nginx。
4. Nginx 配置
5. Nginx命令
# 查询nginx 配置是否正确(可以指定配置文件进行检查)nginx -c /usr/local/nginx/conf/nginx.conf# nginx 重启 可以通过指定文件进行重新启动nginx -s reload -c /usr/local/nginx/conf/nginx.conf# 在bin目录下进行启动./nginx
6. 安装Nginx的服务和自动启动
6.1 安装Nginx服务
本信息保存以nginx命名的文件中并至放至系统/etc/init.d目录下即可
nginx执行文件路径,已调整为本例中路径
nginx=”/usr/local/nginx/sbin/nginx”
nginx配置文件,已调整为本例中路径
NGINX_CONF_FILE=”/usr/local/nginx/conf/nginx.conf”
#!/bin/sh## 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: /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/local/nginx/sbin/nginx"prog=$(basename $nginx)NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginxlockfile=/var/lock/subsys/nginxmake_dirs() {# make required directoriesuser=`$nginx -V 2>&1 | grep "configure arguments:.*--user=" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`if [ -n "$user" ]; thenif [ -z "`grep $user /etc/passwd`" ]; thenuseradd -M -s /bin/nologin $userfioptions=`$nginx -V 2>&1 | grep 'configure arguments:'`for opt in $options; doif [ `echo $opt | grep '.*-temp-path'` ]; thenvalue=`echo $opt | cut -d "=" -f 2`if [ ! -d "$value" ]; then# echo "creating" $valuemkdir -p $value && chown -R $user $valuefifidonefi}start() {[ -x $nginx ] || exit 5[ -f $NGINX_CONF_FILE ] || exit 6make_dirsecho -n $"Starting $prog: "daemon $nginx -c $NGINX_CONF_FILEretval=$?echo[ $retval -eq 0 ] && touch $lockfilereturn $retval}stop() {echo -n $"Stopping $prog: "killproc $prog -QUITretval=$?echo[ $retval -eq 0 ] && rm -f $lockfilereturn $retval}restart() {configtest || return $?stopsleep 1start}reload() {configtest || return $?echo -n $"Reloading $prog: "killproc $prog -HUPretval=$?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" instart)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
# 创建文件, 然后复制到 init.d 文件下面cp nginx /etc/init.d/# 改变文件的权限chmod 755 /etc/init.d/nginx# 添加服务类型chkconfig --add nginx

参考网站:https://www.yuque.com/mxfh3t/iluy1o/dnqsmy/edit?toc_node_uuid=GnyqpNj3iNsAn8nV
