文章目录
一、Yum安装
配置Yum源的官网:http://nginx.org/en/linux_packages.html
关闭防火墙和selinux:
[root@nginx-server ~]# getenforce
Enforcing
[root@nginx-server ~]# setenforce 0
[root@nginx-server ~]# systemctl stop firewalld
[root@nginx-server ~]# systemctl disable firewalld
1、配置nginx的Yum源
(1)安装说明
在新计算机上首次安装nginx之前,需要设置nginx软件包存储库。 之后,您可以从存储库安装和更新nginx。
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
yum install nginx -y
(2)查看是否安装成功
[root@nginx-server yum.repos.d]# nginx -v
nginx version: nginx/1.16.0
(3)启动并设置开机启动
[root@nginx-server ~]# systemctl start nginx
[root@nginx-server ~]# systemctl enable nginx
(4)浏览器输入ip访问:
2、使用epel源
(1)安装epel扩展源
yum -y install epel-release
(2)直接安装nginx(默认安装最新版本)
yum -y install nginx
二、Nginx 编译安装
1、安装编译环境
yum -y install gcc gcc-c++
2、安装pcre软件包(使nginx支持http rewrite模块)
yum install -y pcre pcre-devel
3、安装openssl-devel(使nginx支持ssl)
yum install -y openssl openssl-devel
4、安装zlib
yum install -y zlib zlib-devel
5、创建用户nginx
为保证安全性,为nginx创建一个不登陆的用户
groupadd nginx
useradd nginx -g nginx -s /sbin/nologin -M
6、安装nginx
[root@localhost ~]# wget http://nginx.org/download/nginx-1.16.0.tar.gz
[root@localhost ~]# tar xzf nginx-1.16.0.tar.gz -C /usr/local/
[root@localhost ~]# cd /usr/local/nginx-1.16.0/
[root@localhost nginx-1.16.0]# ./configure --prefix=/usr/local/nginx --group=nginx --user=nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/tmp/nginx/client_body --http-proxy-temp-path=/tmp/nginx/proxy --http-fastcgi-temp-path=/tmp/nginx/fastcgi --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre --with-http_realip_module --with-stream
[root@localhost nginx-1.16.0]# make && make install
7、启动nginx
[root@localhost ~]# /usr/local/nginx/sbin/nginx