Nginx安装部署和开机自启

一般nginx都安装在usr/local下,所以先进入到这个文件夹内

一、下载 nginx 安装包

下载地址:​​​​​​nginx: download

下载图中的版本 

 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值