标题centos7之nginx(一)安装
依赖
# 安装依赖--net模式
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
# 单机模式安装依赖
1)配置iso
sudo mkdir /mnt/iso
sudo mount -o loop CentOS-7-x86_64-Everything-1810.iso /mnt/iso
sudo rm -rf /etc/yum.repos.d/
sudo touch /etc/yum.repos.d/local.repo
vim /etc/yum.repos.d/local.repo
-----------------------------
[local_server]
name=This is a local repo
baseurl=file:///mnt/iso
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
-----------------------------------------------------
yum clean all
yum makecache
2)使用yum
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
yum安装
sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
sudo yum install -y nginx
sudo systemctl enable nginx.service
sudo systemctl start nginx.service
rpm安装
wget https://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.16.1-1.el7.ngx.x86_64.rpm
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
rpm -ivh ginx-1.16.1-1.el7.ngx.x86_64.rpm
编译安装
wget -c https://nginx.org/download/nginx-1.16.1.tar.gz
tar xf nginx-1.16.1.tar.gz
cd nginx-1.16.1
./configure
make && make install
[root@localhost nginx]# whereis nginx
nginx: /usr/local/nginx
#Nginx的启动、停止、动态重载等常用命令如下。
启动:/usr/local/nginx/sbin/nginx
停止:/usr/local/nginx/sbin/nginx -s stop 直接杀死进程
软结束:/usr/local/nginx/sbin/nginx -s quit
测试配置文件正确性:/usr/local/nginx/sbin/nginx -t。
动态重载:/usr/local/nginx/sbin /nginx -s reload,
#配置nginx为开机自启动编辑/etc/rc.d/rc.local文件
[root@localhost nginx]# vim /etc/rc.local
#新增一行
/usr/local/nginx/sbin/nginx
#并修改文件权限。
[root@localhost nginx]# chmod +x /etc/rc.local
#开放防火墙对80端口的限制。
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload
ps:抑或
##下载依赖到文件夹(/opt/nginx_rpm)
yum install --downloadonly --downloaddir=/opt/nginx_rpm gcc zlib zlib-devel pcre-devel openssl openssl-devel
##通过其他方式上传到单机的服务器,执行如下命令
yum localinstall -y /opt/nginx_rpm/*rpm --skip-broken
或者强制安装
rpm -Uvh --force --nodeps /opt/nginx_rpm/*rpm