这种方式是很是简单方便,nginx官网上也有介绍html
http://nginx.org/en/linux_packages.html#RHEL-CentOSlinux
官方说明就是在/etc/yum.repo.d目录下面建立一个nginx的yum源,而后就能够直接用yum install nginx安装了,超级简单,这种方式就直接帮你把服务、都安装好了nginx
[root@iZhp3bt567jwnvj9o9ho7oZ tengine-2.3.2]# yum repolist 已加载插件:fastestmirror Loading mirror speeds from cached hostfile 源标识 源名称 状态 base/7/x86_64 CentOS-7 10,072 epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 13,464 extras/7/x86_64 CentOS-7 448 updates/7/x86_64 CentOS-7 773 repolist: 24,757
[root@iZhp3bt567jwnvj9o9ho7oZ tengine-2.3.2]# cd /etc/yum.repos.d/ [root@iZhp3bt567jwnvj9o9ho7oZ yum.repos.d]# vim nginx.repo
安装源内容c++
[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
[root@iZhp3bt567jwnvj9o9ho7oZ yum.repos.d]# yum repolist 已加载插件:fastestmirror Loading mirror speeds from cached hostfile nginx-stable | 2.9 kB 00:00:00 nginx-stable/7/x86_64/primary_db | 59 kB 00:00:02 源标识 源名称 状态 base/7/x86_64 CentOS-7 10,072 epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 13,464 extras/7/x86_64 CentOS-7 448 nginx-stable/7/x86_64 nginx stable repo 206 updates/7/x86_64 CentOS-7 773 repolist: 24,963
[root@iZhp3bt567jwnvj9o9ho7oZ yum.repos.d]# yum install nginx 已加载插件:fastestmirror Loading mirror speeds from cached hostfile 正在解决依赖关系 --> 正在检查事务 ---> 软件包 nginx.x86_64.1.1.18.0-2.el7.ngx 将被 安装 --> 解决依赖关系完成 依赖关系解决 =========================================================================================== Package 架构 版本 源 大小 =========================================================================================== 正在安装: nginx x86_64 1:1.18.0-2.el7.ngx nginx-stable 769 k 事务概要 =========================================================================================== 安装 1 软件包 总下载量:769 k 安装大小:2.7 M Is this ok [y/d/N]: y Downloading packages: 警告:/var/cache/yum/x86_64/7/nginx-stable/packages/nginx-1.18.0-2.el7.ngx.x86_64.rpm: 头V4 RSA/SHA1 Signature, 密钥 ID 7bd9bf62: NOKEY nginx-1.18.0-2.el7.ngx.x86_64.rpm 的公钥还没有安装 nginx-1.18.0-2.el7.ngx.x86_64.rpm | 769 kB 00:00:59 从 https://nginx.org/keys/nginx_signing.key 检索密钥 导入 GPG key 0x7BD9BF62: 用户ID : "nginx signing key <signing-key@nginx.com>" 指纹 : 573b fd6b 3d8f bc64 1079 a6ab abf5 bd82 7bd9 bf62 来自 : https://nginx.org/keys/nginx_signing.key 是否继续?[y/N]:y Running transaction check Running transaction test Transaction test succeeded Running transaction 正在安装 : 1:nginx-1.18.0-2.el7.ngx.x86_64 1/1 ---------------------------------------------------------------------- Thanks for using nginx! Please find the official documentation for nginx here: * http://nginx.org/en/docs/ Please subscribe to nginx-announce mailing list to get the most important news about nginx: * http://nginx.org/en/support.html Commercial subscriptions for nginx are available on: * http://nginx.com/products/ ---------------------------------------------------------------------- 验证中 : 1:nginx-1.18.0-2.el7.ngx.x86_64 1/1 已安装: nginx.x86_64 1:1.18.0-2.el7.ngx 完毕!
[root@iZhp3bt567jwnvj9o9ho7oZ yum.repos.d]# systemctl enable nginx Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@iZhp3bt567jwnvj9o9ho7oZ yum.repos.d]# systemctl start nginx [root@iZhp3bt567jwnvj9o9ho7oZ yum.repos.d]# ps -ef|grep nginx root 521 1 0 15:36 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf nginx 522 521 0 15:36 ? 00:00:00 nginx: worker process root 702 31879 0 15:36 pts/0 00:00:00 grep --color=auto nginx
systemctl enable nginx #设置nginx为开机启动 systemctl start nginx #启动nginx服务 systemctl stop nginx #中止nginx systemctl restart nginx #重启nginx
Nginx 是 C语言 开发,建议在 Linux 上运行,固然,也能够安装 Windows 版本,本篇则使用 CentOS 7 做为安装环境。正则表达式
安装 nginx 须要先将官网下载的源码进行编译,编译依赖 gcc 环境,若是没有 gcc 环境,则须要安装:算法
yum install gcc-c++
PCRE(Perl Compatible Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库。nginx 的 http 模块使用 pcre 来解析正则表达式,因此须要在 linux 上安装 pcre 库,pcre-devel 是使用 pcre 开发的一个二次开发库。nginx也须要此库。命令:shell
yum install -y pcre pcre-devel
zlib 库提供了不少种压缩和解压缩的方式, nginx 使用 zlib 对 http 包的内容进行 gzip ,因此须要在 Centos 上安装 zlib 库。vim
yum install -y zlib zlib-devel
OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、经常使用的密钥和证书封装管理功能及 SSL 协议,并提供丰富的应用程序供测试或其它目的使用。
nginx 不只支持 http 协议,还支持 https(即在ssl协议上传输http),因此须要在 Centos 安装 OpenSSL 库。centos
yum install -y openssl openssl-devel
①直接下载.tar.gz
安装包,地址:https://nginx.org/en/download.html安全
②使用wget
命令下载(推荐)。确保系统已经安装了wget,若是没有安装,执行 yum install wget 安装。
wget -c http://nginx.org/download/nginx-1.18.0.tar.gz
依然是直接命令: tar -zxvf nginx-1.12.0.tar.gz cd nginx-1.12.0
其实在 nginx-1.12.0 版本中你就不须要去配置相关东西,默认就能够了。固然,若是你要本身配置目录也是能够的。
①.使用默认配置。这个命令会在目录里生成Makefile文件,成功后会在目录生成Makefile跟objs目录
./configure
②.自定义配置(不推荐)
./configure \ --prefix=/usr/local/nginx \ --conf-path=/usr/local/nginx/conf/nginx.conf \ --pid-path=/usr/local/nginx/conf/nginx.pid \ --lock-path=/var/lock/nginx.lock \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --with-http_gzip_static_module \ --http-client-body-temp-path=/var/temp/nginx/client \ --http-proxy-temp-path=/var/temp/nginx/proxy \ --http-fastcgi-temp-path=/var/temp/nginx/fastcgi \ --http-uwsgi-temp-path=/var/temp/nginx/uwsgi \ --http-scgi-temp-path=/var/temp/nginx/scgi
注:将临时文件目录指定为/var/temp/nginx,须要在/var下建立temp及nginx目录
make make install
查找安装路径:
whereis nginx
cd /usr/local/nginx/sbin/ ./nginx ./nginx -s stop ./nginx -s quit ./nginx -s reload