杨海振
当自己的才华撑不起野心时,那就沉下心来学习吧!

下载地址:http://nginx.org/en/download.html

1.YUM安装
vim  /etc/yum.repos.d/nginx.repo
i[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
安装
yum install nginx -y
启用及验证
  nginx
  rpm -ql nginx
  ps -ef | grep nginx
备注:

//收集rpm包方式离线安装

curl -s -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -s -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum makecache fast 
vim /etc/yum.conf 
[main]
..............
keepcache=1
...............
yum install nginx -y
nginx
mkdir nginx_rpm
find /var/cache/yum/x86_64/7/ -name "*.rpm" -type f |xargs -i mv {} nginx_rpm/
cd nginx_rpm/
scp -rp nginx-1.20.2-1.el7.ngx.x86_64.rpm 192.168.20.68:/root/
yum  localinstall   *.rpm  -y
nginx
rpm -ql nginx
2.源码安装
安装依赖环境
[root@server ~]# yum -y install pcre-devel openssl openssl-devel gd-devel

[root@server ~]# yum -y groups install 'Development Tools'
创建日志存放目录
[root@server ~]# mkdir -p /var/log/nginx
[root@server ~]# useradd -r -s /sbin/nologin nginx
[root@server ~]# chown -R nginx.nginx /var/log/nginx/
下载nginx
[root@server ~]# cd /usr/src/
[root@server src]# wget http://nginx.org/download/nginx-1.12.0.tar.gz
编译安装
[root@server ~]# cd /usr/src/
[root@server src]# tar xf nginx-1.12.0.tar.gz
[root@server src]# cd nginx-1.12.0
[root@server nginx-1.12.0]# ./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-debug \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_image_filter_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--http-log-path=/var/log/nginx/access.log \
--error-log-path=/var/log/nginx/error.log

[root@server nginx-1.12.0]# make -j 2 && make install
3.nginx安装后配置配置环境变量
[root@server nginx-1.12.0]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
[root@server nginx-1.12.0]#  . /etc/profile.d/nginx.sh

//注:

[root@nginx-server nginx-1.12.0]# echo $PATH
/usr/local/nginx/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
4.启动nginx
[root@server ~]# nginx
[root@server ~]# ss -antl
posted on 2021-06-10 13:58  沧海浮尘  阅读(44)  评论(0)    收藏  举报