网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

CentOS7安装Nginx并配置自动启动实例分析

今天小编给大家分享一下CentOS7安装Nginx并配置自动启动实例分析的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。

创新互联建站服务项目包括赤壁网站建设、赤壁网站制作、赤壁网页制作以及赤壁网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,赤壁网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到赤壁省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!

1、官网下载安装包

选择适合linux的版本,这里选择最新的版本,下载到本地后上传到服务器或者centos下直接wget命令下载。

CentOS7安装Nginx并配置自动启动实例分析

切换到/usr/local目录,下载软件包

# cd /usr/local
# wget http://nginx.org/download/nginx-1.11.5.tar.gz

2、安装nginx

先执行以下命令,安装nginx依赖库,如果缺少依赖库,可能会安装失败,具体可以参考文章后面的错误提示信息。

# yum install gcc-c++
# yum install pcre
# yum install pcre-devel
# yum install zlib 
# yum install zlib-devel
# yum install openssl
# yum install openssl-devel

解压安装包

# tar -zxvf nginx-1.11.5.tar.gz

nginx被解压到了/usr/local/nginx-1.11.5 目录下(不要把压缩包解压到/usr/local/nginx目录下,或者将解压后的目录重命名为nginx,因为nginx会默认安装到/usr/local/nginx目录下),切换到nginx-1.11.5/目录

# cd /usr/local/nginx-1.11.5/

执行# ./configure

# ./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= option.

    如果出现上面提示,表示缺少pcre库

    ./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= option.

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

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

# make
# make install

没有出错的话,表示nginx已经成功安装完成,默认安装位置为/usr/local/nginx,之前的/usr/local/nginx-1.11.5/可以删除掉了。

如果出现cp: 'conf/koi-win' and '/usr/local/nginx/conf/koi-win' are the same file,可能是你把安装包解压到了/usr/local/nginx目录,解决办法是将该目录重命名为其他名称后再执行make,make install.

3、配置nginx开机启动

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

# cd /lib/systemd/system/
# vim nginx.service

文件内容如下:

[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开机启动

# systemctl enable nginx.service

systemctl start nginx.service    启动nginx

systemctl stop nginx.service    结束nginx

systemctl restart nginx.service    重启nginx

4、验证是否安装成功

输入http://服务器ip/ 如果能看到nginx的界面,就表示安装成功了

CentOS7安装Nginx并配置自动启动实例分析

以上就是“CentOS7安装Nginx并配置自动启动实例分析”这篇文章的所有内容,感谢各位的阅读!相信大家阅读完这篇文章都有很大的收获,小编每天都会为大家更新不同的知识,如果还想学习更多的知识,请关注创新互联行业资讯频道。


本文标题:CentOS7安装Nginx并配置自动启动实例分析
转载来于:http://bjjierui.cn/article/gphscg.html

其他资讯