操作系统:CentOS 6.9
nginx版本:1.14.0
1. 安装依赖环境
1.1 安装gcc
yum install gcc-c++
1.2 安装其他依赖
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
2. 下载安装nginx
2.1 下载并解压nginx安装包
wget http://nginx.org/download/nginx-1.14.0.tar.gz
tar –zxvf nginx-1.14.0.tar.gz –C /usr/local
2.2 编译安装
进入nginx-1.14.0的目录,然后执行./configure命令
# --prefix可以指定安装目录
./configure --prefix=/usr/local/nginx
make & make install
3. 启动及测试
3.1 启动nginx
/usr/local/nginx/sbin/nginx
# 启动完毕查看是否启动成功
ps -ef | grep nginx
# 效果
root 19945 1 0 Apr23 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
www 19946 19945 0 Apr23 ? 00:00:00 nginx: worker process
www 19947 19945 0 Apr23 ? 00:00:00 nginx: worker process
root 20859 20835 0 09:46 pts/0 00:00:00 grep --color=auto nginx
如果要关闭nginx
/usr/local/nginx/sbin/nginx -s stop
重新热启动nginx
/usr/local/nginx/sbin/nginx -s reload
3.2 测试nginx欢迎页面
在地址栏输入http://ip或者http://ip:80通过浏览器访问nginx欢迎页,如下图所示