一. 安装 nginx
1. 准备 1.8.0 安装包
nginx-1.8.0.tar.gz
2. 安装第三方依赖
- yum install gcc-c++
- yum install -y pcre pcre-devel
- yum install -y zlib zlib-devel
- yum install -y openssl openssl-devel
3. 解压安装包并进入 nginx 目录
- tar zxf nginx-1.8.0.tar.gz
- cd nginx-1.8.0
4. 使用 configure 命令在 nginx 目录中创建 makeFile 文件
./configure --prefix=/usr/local/nginx --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_gzip_static_module --http-client-body-temp-path=/var/temp/nginx/client --http-proxy-temp-path=/var/temp/nginx/proxy --http-fastcgi-temp-path=/var/temp/nginx/fastcgi --http-uwsgi-temp-path=/var/temp/nginx/uwsgi --http-scgi-temp-path=/var/temp/nginx/scgi
5. 在 / var 下创建 temp 及 nginx 目录
注意: 第 4 步将临时文件目录指定为 / var/temp/nginx, 所以在启动 nginx 之前, 需要在 / var 下创建 temp 及 nginx 目录
mkdir /var/temp/nginx/client -p
6. 编译 nginx 源文件, 在 nginx 目录下执行 make 命令
make
7. 运行编译后的文件
make install
8. 查看已安装的 nginx
注意: 安装好的 nginx 在 / usr/local / 下
cd /usr/local/ ll
二. 启动 nginx
1. 进入 nginx 的 sbin 目录后启动
- cd /usr/local/nginx/sbin
- ./nginx
2. 查看是否启动
注意: 存在 master 和 worker 进程说明启动成功
ps wux|grep nginx
3. 通过浏览器访问 nginx
注意: 默认端口 80, 这里的 ip 地址是虚拟机上 linux 的 ip 地址
http://192.168.18.107/
三. 关闭 nginx
- cd /usr/local/nginx/sbin
- ./nginx -s quit
四. 重启 nginx
注意: 可以用于刷新配置文件, 先关闭后启动
- cd /usr/local/nginx/sbin
- ./nginx -s reload
来源: http://www.bubuko.com/infodetail-2742481.html