centos7安装Nginx

1、官网下载安装包

    http://nginx.org/en/download.html,选择适合Linux的版本,选择最稳定的版本,下载到本地后用winscp上传到服务器

切换到/usr/local目录、

解压tar -zxvf nginx-1.11.5.tar.gz

cd /usr/local/nginx-1.11.5/

执行# ./configure

    该操作会检测当前系统环境,以确保能成功安装nginx,执行该操作后可能会出现以下几种提示:

    checking for OS

     + Linux 3.10.0-123.el7.x86_64 x86_64

    checking for C compiler ... not found

    ./configure: error: C compiler cc is not found

    如果出现以上错误提示信息,执行yum install gcc-c++安装gcc,

  ./configure: error: the HTTP rewrite module requires the PCRE library.

    You can either disable the module by using --without-http_rewrite_module

    option, or install the PCRE library into the system, or build the PCRE library

    statically from the source with nginx by using --with-pcre=<path> option.

    如果出现上面提示,表示缺少PCRE库执行以下代码安装pcre

yum  -y install  pcre pcre-devel

    ./configure: error: the HTTP gzip module requires the zlib library.

    You can either disable the module by using --without-http_gzip_module

    option, or install the zlib library into the system, or build the zlib library

    statically from the source with nginx by using --with-zlib=<path> option.

    如果出现以上提示,表示缺少zlib库

yum -y install zlib zlib-devel

    如果没有出现./configure: error提示,表示当前环境可以安装nginx,执行make和make install编译nginx

3、配置nginx开机启动

    切换到/lib/systemd/system/目录,创建nginx.service文件vim nginx.service

1

2

# cd /lib/systemd/system/

# vim nginx.service

文件内容如下:

1

2

3

4

5

6

7

8

9

10

11

12

13

[Unit]

Description=nginx 

After=network.target 

   

[Service] 

Type=forking 

ExecStart=/usr/local/nginx/sbin/nginx

ExecReload=/usr/local/nginx/sbin/nginx reload

ExecStop=/usr/local/nginx/sbin/nginx quit

PrivateTmp=true 

   

[Install] 

WantedBy=multi-user.target

    退出并保存文件,执行systemctl enable nginx.service使nginx开机启动

1

# systemctl enable nginx.service

systemctl start nginx.service    启动nginx

systemctl stop nginx.service    结束nginx

systemctl restart nginx.service    重启nginx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值