cent7配置nginx(一),nginx编译安装

来源:互联网 发布:jquery数组push对象 编辑:程序博客网 时间:2024/06/01 08:01

image

说明:本文章内容已经在CentOS Linux release 7.3.1611 (Core)上测试通过。

访问nginx官网下载适合的nginx版本,使用tar命令解压,进入解压目录执行

./configure

在centos7.3执行上面命令会出现如下错误,

错误内容1:

./configure: error: the HTTP rewrite module requires the PCRE library.You can either disable the module by using --without-http_rewrite_moduleoption, or install the PCRE library into the system, or build the PCRE librarystatically from the source with nginx by using --with-pcre=<path> option.

解决方法:

yum -y install pcre-devel

错误内容2:

./configure: error: the HTTP gzip module requires the zlib library.You can either disable the module by using --without-http_gzip_moduleoption, or install the zlib library into the system, or build the zlib librarystatically from the source with nginx by using --with-zlib=<path> option.

解决方法:

yum install -y zlib-devel

错误内容23

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

解决方法:

yum install gcc

接着执行

./configuremakemake install

安装便可成功。

进入/usr/local/nginx/sbin执行./nginx可以启动nginx,执行netstat -nlp可以看到80端口已经被监听,在浏览器输入http://127.0.0.1可以看到Welcome to nginx!表示nginx已经启动成功。

nginx环境变量配置

每次操作nginx都需要进入/usr/local/nginx/sbin目录中,过于繁琐,因此可以在通过配置nginx环境变量解决,如下配置,执行

vim /etc/profile

打开环境配置文件,

HGINX_HOME=/usr/local/nginx/sbinPATH=$PATH:$HGINX_HOME:export PATH

修改好以后,执行source /etc/profile是配置生效。

最后附上安装nginx必备的所有的库,如果在编译安装nginx报错的情况下请检查如下库

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

nginx常用命令参考:http://www.jb51.net/article/47750.htm