一般nginx都安装在usr/local下,所以先进入到这个文件夹内
一、下载 nginx 安装包
下载图中的版本
wget -c https://nginx.org/download/nginx-1.26.1.tar.gz
二、安装nginx
1.安装依赖
yum install gcc-c++
yum -y install zlib zlib-devel
yum -y install openssl openssl-devel
yum -y install pcre pcre-devel
yum install -y gcc make perl-ExtUtils-MakeMaker perl-IPC-Cmd
2.解压nginx(自己的安装包)
tar -zxvf nginx...
修改nginx-1.26.1 为nginx
mv nginx-1.26.1 nginx
cd nginx
3.执行编译命令
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
对nginx编译和安装
make & make install
4.关闭防火墙和selinux(关了的直接跳过)
systemctl stop firewalld关闭防火墙
systemctl disable firewalld开机禁用防火墙
永久关闭selinux:vim /etc/selinux/config
(我已经改了,反正就是在这个位置改成disabled)
reboot重启服务器
启动nginx
cd /usr/local/nginx/sbin
./nginx
三、访问nginx界面
自己IP+端口号(默认80)
或者curl+ip+端口
启动不了大概率是没有logs文件
cd /usr/local/nginx
mkdir logs
./nginx -t 检查配置文件
./usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf 引用配置文件
四、开机自启
vi /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx - web server
After=network.targt
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
保存
重新加载systemd配置文件
systemctl daemon-reload
启动
systemctl start nginx
开启自启
systemctl enable nginx.service