Nginx安装

一、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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值