目录
4.在/etc/yum.repos.d 下创建yum存储库:nginx.repo
1.安装依赖包
yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
2.网站下载软件包
根据需要在官网下载软件包
https://nginx.org/en/download.html
3.创建路径
mkdir /usr/local/nginx
cd /usr/local/nginx
wget https://nginx.org/download/nginx-1.25.3.tar.gz
tar -zxvf nginx-1.25.3.tar.gz
cd nginx-1.25.3
./configure --prefix=/usr/local/nginx
#不需要输,只是联网安装的参数,方便个人查询而已
--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 \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-file-aio \
--with-http_realip_module
参数详细信息参照官网的文档:https://nginx.org/en/docs/configure.html
make && make install
4.通过创建yum参考方式安装
vim /etc/nginx.repo
[nginx-stable] name=nginx stable repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true [nginx-mainline] name=nginx mainline repo baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/ gpgcheck=1 enabled=0 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true
官方文档:https://nginx.org/en/linux_packages.html#RHEL
yum install -y yum-utils yum install -y nginx#该方法需要联网,而且安装的版本未必是你要的版本,但该方法简单粗暴,不需要配置systemctl服务和环境变量
5.启动nginx
cd /usr/local/nginx/sbin
./nginx
6.关闭防火墙
直接关闭防火墙:
systemctl stop firewalld
或者开启相应端口
firewall-cmd --zone=public --add-port=80/tcp --permanent #放行80端口
firewall-cmd --reload #重载防火墙
网页查看服务是否正常
表示服务正常
./nginx -s stop #关闭nginx
7、配置systemctl服务和环境变量
#配置systemctl服务
vim /lib/systemd/system/nginx.service[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID[Install]
WantedBy=multi-user.targesystemctl daemon-reload #重载配置文件
#配置环境变量
echo ' export PATH=$PATH:/usr/local/nginx/sbin ' >> /etc/profile
nginx -V #查看版本