LNMP之Nginx安装(centos6.8)

一. Nginx介绍 :

1)Nginx(发音同 engine x)是一款轻量级的 Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个 BSD-like 协议下发行,可以在 UNIX、GNU/Linux、BSD、Mac OS X、Solaris,以及 Microsoft Windows 等操作系统中运行。

2)  Nginx 是一款面向性能设计的 HTTP 服务器,相较于 Apache、lighttpd 具有占有内存少,稳定性高等优势。

 

二. Nginx安装

# 首先确认是不是有安装编译包和一些依赖包
# yum install gcc gcc-c++ openssl openssl-devel zib-devel zib

安装pcre (nginx重写需要)

* pcre下载地址:https://sourceforge.net/projects/pcre/files/pcre/   可根据需要下载需要版本.

// 下载pcre包选用版本8.41

# wget https://jaist.dl.sourceforge.net/project/pcre/pcre/8.41/pcre-8.41.tar.gz

// 解压 

# tar zxvf pcre-8.41.tar.gz
// 切换到目录进行编译安装
# cd pcre-8.41

// 安装目录设定 
# ./configure --prefix=/usr/local/pcre  

// 执行编译和安装
# make && make install

安装nginx

同样首先去nginx官网nginx.org选取合适的版本进行下载  http://nginx.org/en/download.html

// 下载nginx包

# wget http://nginx.org/download/nginx-1.18.0.tar.gz

// 解压 

# tar -zxvf nginx-1.18.0.tar.gz

// 切换到源码目录进行安装
# cd nginx-1.18.0
# ./configure --prefix=/usr/local/nginx --with-pcre=/usr/local/zip/pcre-8.41(这为pcre的源码目录) --with-http_stub_status_module
# make && make install

#到这还没有完成,需要指定nginx配置文件,否则会报错:

nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)

// 需要指定nginx运行配置文件,以下命令解决 

# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/nginx.conf

检查nginx配置文件语法有没问题
#/usr/local/nginx/sbin/nginx -t
如果没有会出现,下面提示
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

启动nginx
#/usr/local/nginx/sbin/nginx
重新加载nginx
#/usr/local/nginx/sbin/nginx –s reload  平滑重启

 至此已安装完成nginx,ip进行访问出先以上页面则表示nginx安装成功.

------------------------------------- 安装中报错解决 --------------------------------------

1.解决nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed错误 

# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

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

#yum -y install pcre-devel

至此,nginx安装完成,如有不同见解可留言交流。

 

原文地址:https://www.cnblogs.com/victorcode/p/8275377.html