1 下载
http://nginx.org/download/nginx-1.8.1.tar.gz
2 安装
安装依赖
yum -y install gcc-c++ zlib zlib-devel openssl openssl-devel pcre pcre-devel
创建目录
mkdir -p /root/{services,packages}
解压
tar -xvf /root/packages/nginx-1.8.1.tar.gz -C /root/packages
安装
cd /root/packages/nginx-1.8.1
./configure --prefix=/root/services/nginx --with-http_stub_status_module --with-http_ssl_module
make -j4 && make install
3 设置环境变量
vim ~/.bashrc
export NGINX_HOME=/root/services/nginx
export PATH=$PATH:$NGINX_HOME/sbin
4 验证
nginx -h
5 修改配置文件
用户不能是nobody,否则访问403
vim /root/services/nginx/conf/nginx.conf
user root;
验证配置文件是否正确
nginx -t
6 启动和停止
nginx
验证是否启动
ps -ef | grep nginx
停止
nginx -s stop
7 访问
8 问题
查看日志
tailf -n 1000 /root/services/nginx/logs
9 常见命令
查看版本:nginx -v
启动:nginx
停止:nginx -s stop
验证配置文件:nginx -t
重新加载配置文件:nginx -s reload