本文基于centos8编译安装nginx1.17.4

安装依赖包

[root@centos8 ~]# yum -y install apr* autoconf automake bison bzip2 bzip2* cpp curl curl-devel fontconfig fontconfig-devel freetype-devel gcc gcc-c++ gd gd-devel gettext gettext-devel glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_err-devel libpng libpng-devel libjpeg* libsepol-devel libselinux-devel libstdc++-devel libtool* libgomp libxml2 libxml2-devel libXpm* libxml* libXaw-devel libXmu-devel libtiff libtiff* make openssl openssl-devel patch pcre-devel perl php-common php-gd policycoreutils telnet wget zlib-devel ncurses-devel libtirpc-devel gtk* ntpstat na* bison*

下载源码包

[root@centos8 ~]# wget http://nginx.org/download/nginx-1.17.4.tar.gz
[root@centos8 ~]# tar xf nginx-1.17.4.tar.gz
[root@centos8 ~]# ls
anaconda-ks.cfg       mysql80-community-release-el8-1.noarch.rpm  nginx-1.17.4.tar.gz
initial-setup-ks.cfg  nginx-1.17.4

创建用户

[root@centos8 ~]# groupadd www
[root@centos8 ~]# useradd -g www www -M -s /sbin/nologin

安装nginx

#创建安装目录
[root@centos8 ~]# mkdir -p /application/nginx
#进入nginx安装目录,下载nginx_upstream_check_module模块
[root@centos8 ~]# cd /application/nginx
#下载nginx_upstream_check_module模块

[root@centos8 nginx]# wget https://codeload.github.com/yaoweibin/nginx_upstream_check_module/zip/master
#解压
[root@centos8 nginx]# unzip master


#编译安装
[root@centos8 nginx-1.17.4]# cd nginx-1.17.4
[root@centos8 nginx-1.17.4]# ./configure \
--prefix=/application/nginx/ \
--user=www \
--group=www \
--with-pcre \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-mail \
--with-mail_ssl_module \
--with-stream_ssl_module \
--add-module=/application/nginx/nginx_upstream_check_module-master
[root@centos8 nginx-1.17.4]# make & make install

/application/nginx/sbin/nginx             启动
/application/nginx/sbin/nginx -s stop     停止
/application/nginx/sbin/nginx -s reload   重启

#添加软连接
[root@lnmp system]# ln -s /application/nginx/sbin/nginx /usr/bin/

设置开机自启

[root@centos8 ~]# cd /usr/lib/systemd/system

路径启动(不用管这个,当忘记快捷启动了再来看这个)
/application/nginx/sbin/nginx             启动
/application/nginx/sbin/nginx -s stop     停止
/application/nginx/sbin/nginx -s reload   重启

[root@centos8 system]# vim nginx.service
[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
ExecStart=/application/nginx/sbin/nginx
ExecReload=/application/nginx/sbin/nginx -s reload
ExecStop=/application/nginx/sbin/nginx -s quit

[Install]
WantedBy=multi-user.target
[root@centos8 system]# systemctl enable nginx
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.

这两个命令留意下
systemctl disable  nginx.service        #禁止开机自启
systemctl s-enable nginx.service        #查询是否为开机自己服务

快速启动ningx命令
 systemctl start  nginx.service         #启动
 systemctl stop   nginx.service         #停止
 systemctl reload nginx.service         #重启
 systemctl status nginx.service         #查看服务状态
文章作者: 鲜花的主人
版权声明: 本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 爱吃可爱多
Nginx Nginx
喜欢就支持一下吧
打赏
微信 微信
支付宝 支付宝