安装linux系统的nignx
问题描述
提示:这里描述项目中遇到的问题:
安装几次出现的安装不了
安装4个依赖出现:Failed to download metadata for repo ‘PowerTools‘: Cannot prepare internal mirrorlist: No URLs in mi 这个问题。
直接solution:
首先建立一个备份文件夹
makedir /tmp/yum
然后备份文件
cd /etc/yum.repos.d mv *.repo /tmp/yum
然后安装阿里源
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
然后清除yum缓存再重新生成yum缓存
yum clean all yum makecache
如果报如下类似错误
提示:Timeout was reached for
http://mirrors.aliyuncs.com/centos/8/BaseOS/x86_64/os/repodata/repomd.xml
[Connection timed out after 30000 milliseconds] Could not resolve
host: mirrors.cloud.aliyuncs.com
执行以下代码
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
二、接下来就是安装nginx:
1.安装依赖包
//一键安装上面四个依赖 yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
2.下载并解压安装包
//创建一个文件夹 cd /usr/local mkdir nginx cd nginx //下载tar包 wget http://nginx.org/download/nginx-1.13.7.tar.gz tar -xvf nginx-1.13.7.tar.gz
3.安装nginx
//进入nginx目录 cd /usr/local/nginx //进入目录 cd nginx-1.13.7 //执行命令 考虑到后续安装ssl证书 添加两个模块 ./configure --with-http_stub_status_module --with-http_ssl_module //执行make命令 make //执行make install命令 make install
4.启动nginx服务
/usr/local/nginx/sbin/nginx
4.配置nginx.conf
这里根据需要配置:
# 打开配置文件 vi /usr/local/nginx/conf/nginx.conf
5.重启nginx
/usr/local/nginx/sbin/nginx -s reload
查看nginx进程是否启动:
ps -ef | grep nginx
6.若想使用外部主机访问nginx,需要关闭服务器防火墙或开放nginx服务端口,端口为上一步nginx.conf的配置端口:
centOS6及以前版本使用命令: systemctl stop iptables.service
centOS7关闭防火墙命令: systemctl stop firewalld.service
关闭防火墙会导致服务器有一定风险,所以建议是单独开放服务端口 :
开放80端口:
firewall-cmd --zone=public --add-port=80/tcp --permanent
查询端口号80 是否开启:
firewall-cmd --query-port=80/tcp
重启防火墙:
firewall-cmd --reload
随后访问该ip:端口 即可看到nginx界面。
7.访问服务器ip查看(备注,由于我监听的仍是80端口,所以ip后面的端口号被省略)
这里直接出来nginx的那个yemain
8、nginx常用命令:
/usr/local/nginx/sbin/nginx -s reload //重新加载 /usr/local/nginx/sbin/nginx -s stop //关闭 /usr/local/nginx/sbin/nginx //启动



