1. 安装nginx依赖
首先安装nginx的依赖
yum install gcc gcc-c++ openssl openssl-devel cyrus-sasl-md5
2,创建nginx用户
如果没有nginx,启动nginx时会报错
[root@localhost nginx-1.11.2]# /usr/local/nginx/sbin/nginx nginx: [emerg] getpwnam("nginx") failed
groupadd nginx
useradd -s /sbin/nologin -g nigix -M nginx
3,下载最新版nginx安装包
wget -C http://nginx.org/download/nginx-1.12.0.tar.gz
4,解压
tar zxvf nginx-1.12.0.tar.gz
5,进入nginx目录
cd nginx-1.12.0
6,编译设置
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module
因此要顺利的通过nginx编译安装必须安装的依赖关系有:
yum install gc gcc gcc-c++ pcre-devel zlib-devel openssl-devel
如果有错误提示:./configure: error: C compiler cc is not found
解决方法:
yum install gcc gcc-c++
如果有错误提示:./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.
解决方法:
yum install pcre-devel
如果有错误提示:./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using –with-openssl=<path> option.
解决方法:
yum install openssl-devel
7,编译&安装
make & make install
8,nginx直接启动方法
/usr/local/nginx/sbin/nginx
9,现在我们将nginx加入到环境变量中
vi /etc/profile
随后我们更新环境变量 并使用命令再次重启nginx
写在结尾:可能会出现没有pid文件的情况
[emerg]: getpwnam(“nginx”) failed
1 2 | [root@localhost nginx-1.11.2] # /usr/local/nginx/sbin/nginx nginx: [emerg] getpwnam( "nginx" ) failed |