1.下载nginx
- 官方网站:http://nginx.org/
- Nginx在Linux下安装,只提供了源代码,所以我们需要进行编译
2. 安装环境配置
- 因为Nginx是C语言编写的,所以需要配置C语言编译环境 (一定要在联网状态下安装),需要安装gcc的环境。执行命令:
yum install gcc-c++
注意: 如果执行命令出现这样的提示:
问题: yum在锁定状态中,强制关掉yum进程即可
解决办法:
rm -f /var/run/yum.pid
- 第三方的开发包, 在编译之前需要安装这些第三方包
PCRE
nginx的http模块使用pcre来解析正则表达式,所以需要在linux上安装pcre库
yum install -y pcre pcre-devel
- zlib
nginx使用zlib对http包的内容进行gzip,所以需要在linux上安装zlib库
yum install -y zlib zlib-devel
- openssl
OpenSSL 是一个强大的安全套接字层密码库,nginx不仅支持http协议,还支持https,所以需要在linux安装openssl库
yum install -y openssl openssl-devel
3.2 安装Nginx 步骤
-
将Nginx的源码包上传到 Linux
-
解压Nginx
tar -zxvf nginx-1.17.8.tar
3.进入到解压之后的目录 nginx-1.17.8
4.执行命令 configure,生成 Mikefile 文件
./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
- 执行命令后, 生成了MakeFile文件
- 创建临时文件目录
mkdir /var/temp/nginx/client -p
- 执行make命令,进行编译
make
- 安装
make instal
4. 启动并访问 Nginx
- 进入到nginx 安装目录
cd /usr/local/nginx/
- 进入到 sbin目录,执行
nginx
命令
./nginx 启动
./nginx -s stop 关闭
ps aux | grep nginx 查看进程
- 通过浏览器进行访问 ,默认端口 80 (注意:是否关闭防火墙。)