时间:2021-10-28 作者:冰城心无泪 分类: Linux应用
yum -y install yum-utils
vi /etc/yum.repos.d/nginx.repo
将下列内容复制到文件保存
[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
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
或者复制下面内容直接创建
cat > /etc/yum.repos.d/nginx.repo << 'EOF'
[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
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
EOF
创建缓存
yum makecache
yum install nginx
Nginx安装完成后,默认配置文件即主配置文件路径
/etc/nginx/nginx.conf
在默认配置文件内,只有全局块、events块、http块,server块及location块配置为下面的配置文件
/etc/nginx/conf.d/default.conf
当然,我们也可以根据需要修改默认配置文件或者在/etc/nginx/conf.d/目录下创建其他后缀为.conf的配置文件,在nginx的主配置文件中有说明,包含/etc/nginx/conf.d/目录下后缀为.conf的配置文件。
systemctl start nginx
systemctl stop nginx
systemctl enable nginx
firewall-cmd --set-default-zone=public
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
service iptables save
service iptables restart
下面附上Nginx官方文档的地址
https://nginx.org/en/linux_packages.html