CentOS7使用yum安装Nginx

文章目录

  • CentOS7使用yum安装Nginx
    • 安装说明
    • 安装gcc
    • 安装pcre库
    • 安装zlib库
    • 安装OpenSSL库
    • 安装Nginx库
    • 启动nginx

安装说明

  • Nginx是一款轻量级的网页服务器、反向代理服务器。相较于Apache、lighttpd具有占有内存少,稳定性高等优势。
    它最常的用途是提供反向代理服务。
  • 在Centos下,yum源不提供nginx的安装,不能直接 yum install nginx进行安装,但可以通过切换yum源的方法获取安装。也可以通过直接下载安装包的方法
  • 安装必要的库(nginx 中gzip模块需要 zlib 库,rewrite模块需要 pcre 库,ssl 功能需要openssl库),具体版本号根据实际情况改变。这里其他的库就默认安装,我们选定 /usr/local 为nginx的安装目录

安装gcc

查看是否有gcc

gcc -v

如果是新环境,一般没有gcc,都需要进行安装

yum install -y gcc gcc-c++

如果中间有提示install need space 20M 之类的信息
对于 Is this ok?[y/d/N] 的选择,输入y,即yes的意思。

之后遇到有此类提示都选择yes

安装pcre库

输入命令:

yum install pcre pcre-devel

如果报错:configure: error: You need a C++ compiler for C++ support

回到上一步,安装上gcc就好了

安装库的过程中可能会遇到以下错误:

Error: Multilib version problems found. This often means that the root
cause is something else and multilib version checking is just
pointing out that there is a problem. Eg.:

  1. You have an upgrade for pcre which is missing some dependency that another package requires. Yum is trying to solve this by installing an older version of pcre of the different architecture. If you exclude the bad architecture yum will tell you what the root cause is (which package requires what). You can try redoing the upgrade with --exclude zlib.otherarch … this should give you an error message showing the root cause of the problem.
  2. You have multiple architectures of pcre installed, but yum can only see an upgrade for one of those architectures. If you don’t want/need both architectures anymore then you can remove the one with the missing update and everything will work.
  3. You have duplicate versions of pcre installed already. You can use “yum check” to get yum show these errors. …you can also use --setopt=protected_multilib=false to remove this checking, however this is almost never the correct thing to do as something else is very likely to go wrong (often causing much more problems).

上述常见原因是有两个版本的库。

用以下命令查看pcre库:

rpm -qa | grep pcre

一般结果会是两个库

pcre-8.32-17.el7.x86_64

pcre-8.32-17.el7.i686

用以下命令删除其中一个版本(这里我们删除i686)

yum erase pcre-8.32-17.el7.i686

当我们再次使用rpm命令查看pcre库时,就只剩下x86_64库了

安装zlib库

输入命令:

yum install zlibe zlib-devel

我们在安装的过程中可能会碰到和安装pcre库一样的问题,也是采用一样的解决方法,将命令中的pcre换成zlib就行

安装OpenSSL库

输入命令:

yum install openssl openssl-devel

安装Nginx库

1. 来到/usr/local 文件夹

cd /usr/local/

2. 下载nginx的安装包

wget http://nginx.org/download/nginx-1.8.0.tar.gz

如果系统没有安装wget,执行 yum install wget 命令安装wget,然后再下载nginx的安装包。

这里我装的是nginx的1.8.0版本,大家可以去查nginx的版本然后安装新版,比如nginx-1.12.0,对应修改即可

3. 解压

tar -zxvf nginx-1.8.0.tar.gz

4. 来到nginx-1.8.0 文件夹

cd nginx-1.8.0

5. 配置

./configure

这是我们采用的是默认配置,在 nginx-1.12.0 版本中你就不需要去配置相关东西,默认就可以了。

6. 编译安装

make

make install

7. 查找安装路径

whereis nginx

如果不知道nginx装在哪里了,使用whereis命令进行查找

8. 启动、停止nginx

进入nginx的启动目录

cd /usr/local/nginx/sbin/

下面是四种对nginx的操作:

  1. 启动nginx

./nginx

  1. 关闭nginx。stop是先查出nginx进程id再使用kill命令强制杀掉进程。

./nginx -s stop

  1. 关闭nginx。quit是待nginx进程处理任务完毕再进行停止。

./nginx -s quit

  1. 重新加载nginx

./nginx -s reload

重启时推荐先使用quit/stop关闭,再启动nginx

如果是修改了nginx.conf中的配置信息,想让配置生效。不必关闭nginx,用reload重新加载即可


启动nginx

进入nginx的启动目录下启动nginx

最后一步,在浏览器中输入自己的ip地址(默认80端口),如果看到 Welcome to Nginx 界面,即配置成功。

CentOS7使用yum安装Nginx相关推荐

  1. centos7通过yum安装nginx

    yum install -y nginx 通过yum安装的时候提示下面的错误 [root@localhost yum.repos.d]# yum install nginx已加载插件:fastestm ...

  2. centos7 nginx配置php7,centos7下yum安装nginx和php7和php-fpm

    安裝 nginxCentOS 7 沒有內建的 nginx,所以先到 nginx官網 http://nginx.org/en/linux_packages.html ,找到 CentOS 7 的 ngi ...

  3. centos7通过yum安装nginx以及其简单配置使用

    干货!干货!干货! 执行命令: $ yum install -y nginx 通过yum安装的时候提示下面的错误: [root@localhost ~]# yum install nginx 已加载插 ...

  4. 【CNMP系列】CentOS7.0下安装Nginx服务

    [CNMP系列]CentOS7.0下安装Nginx服务 话步前言,CNMP之路,系统起步:http://www.cnblogs.com/riverdubu/p/6425028.html 这回我来讲解下 ...

  5. CentOS下yum安装nginx服务

    添加nginx的yum源 rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ng ...

  6. CentOS7用yum安装软件报:Cannot find a valid baseurl for repo: base/7/x86_64

    CentOS7用yum安装软件报:Cannot find a valid baseurl for repo: base/7/x86_64 问题:Cannot find a valid baseurl ...

  7. centos7 go yum 安装_超详细的centos7下载安装Postgresql11(yum安装)教程

    概述 新项目准备用PG数据库,实际上也是练手用的,后面用好了再做mysql到PG的迁移,今天主要记录一下centos7用yum安装Postgresql11的过程. 1.到官网查看yum支持到哪个版本的 ...

  8. linux下yum安装pgsql,CentOS7使用yum安装PostgreSQL和PostGIS的方法

    1.更新yum源 CentOS7默认yum源的PostgreSQL版本过低,不适合在本版本上使用.在https://yum.postgresql.org/repopackages.php上找到适合Ce ...

  9. Centos7通过yum安装jdk8

    1.Centos7通过yum安装jdk8 2.Centos7通过yum安装jdk8 转载于:https://www.cnblogs.com/linjiqin/p/11459529.html

最新文章

  1. 论网站长尾关键词优化的六大方法
  2. HDU 3397 Sequence operation
  3. 模拟Spring如何在WEB中运行
  4. 前端含金量较高的网站推荐
  5. 获取Class对象方式
  6. 比特币中的密码学知识汇总
  7. linux 命令查看块设备,系统运维|用 Linux blkid 命令查找块设备详情
  8. GCC 放弃将代码贡献版权强制转让给 FSF!
  9. qt-opensource-windows-x86-vs2010-4.8.6 + qt-creator-windows-opensource-2.8.0
  10. h3c配置snmp配置命令_配置单元命令
  11. 计数器matlab,MATLAB中的几个时间计数器
  12. php使用gd库合并图片,php使用GD库合并简单图片并变动部分颜色
  13. 电子技术在计算机的应用与未来展望,电子信息技术的应用特点与未来发展趋势研究...
  14. python爬虫——爬取小说
  15. linux文件系统与日志文件
  16. 如何搭建企业报表管理系统?
  17. 介绍 Go 断续器(Tickers)
  18. win7计算机里不显示摄像头,win7没有摄像头图标怎么办|win7显示摄像头图标的方法...
  19. 测试的职责是什么,就是不当背锅侠
  20. 多个excel文件不在一个视图里分开独立显示

热门文章

  1. spring-session使用教程(一):redis共享session
  2. C++:=default一些说明
  3. 原型模式、模板方法、迪米特法则、外观模式
  4. Java 洛谷 P1909 买铅笔讲解
  5. aspx网页背景图片设置代码_python 30行代码自动填写问卷(单选题和多选题)
  6. android推送接口,推送API
  7. 综合布线系统技术培训资料
  8. mysql 数据目录迁移_MySQL数据库数据文件路径迁移步骤
  9. 在mysql中怎样设置值唯一_mysql怎么设置行值唯一?
  10. tv英语域名注册_企业邮箱十万个为什么——域名篇