安装Nginx服务需要的依赖包:
yum -y install gcc gcc-c++ pcre pcre-devel openssl openssl-devel zlib zlib-devel
下载Nginx包:
wget https://nginx.org/download/nginx-1.18.0.tar.gz
tar -xvf nginx-1.18.0.tar.gz -C /usr/local/
创建用户:
useradd nginx
进入Nginx目录内
cd /usr/localnginx-1.18.0
配置编译:
./configure --prefix=/usr/local/nginx --group=nginx --user=nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/tmp/nginx/client_body --http-proxy-temp-path=/tmp/nginx/proxy --http-fastcgi-temp-path=/tmp/nginx/fastcgi --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre --with-http_realip_module --with-stream
执行make && make install
/usr/loacl/nginx/sbin/nginx #启动nginx
定义PATH变量:
vim /etc/profile
NGINX_HOME=/usr/loacl/nginx
export PATH=¥NGINX_HOME/sbin:$PATH
source /etc/profile #刷新PATH环境变量配置
nginx -V #查看版本信息和模块 -v只查看版本信息
nginx -t #查看配置文件是否有误
nginx #启动nginx
systemctl stop firewalld #临时关闭防火墙
setenforce 0 #临时关闭selinux
编译安装配置子配置:include /etc/nginx/conf.d/*.conf