1. 下载nginx
官网下载压缩包 nginx: download
我这里直接使用wget下载,选择的是1.18版本
wget https://nginx.org/download/nginx-1.18.0.tar.gz
解压
tar -zxvf nginx-1.18.0.tar.gz
2. 编译
首先安装nginx依赖环境,gcc pcre和openssl
yum -y install gcc gcc-c++ pcre-devel openssl openssl-devel
进入目录
cd nginx-1.18.0
运行配置
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-stream
默认的安装路径是/usr/local/nginx, --prefix=/usr/local/nginx 来指定安装目录
成功后执行
make&make install
3.启动nginx
cd /usr/local/nginx/conf
根据需要修改nginx.conf文件
启动nginx
cd /usr/local/nginx/sbin/
./nginx
如果修改了配置文件,执行
./nginx -s reload
重新加载配置