【Linux】Linux8 | CentOS8 | 安装Nginx

一、准备工作

        1、服务器,不用说

        2、连接控制,XShell或SecureCRT

二、方案一

yum install nginx

三、重点:方案二

1、安装依赖

yum -y install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel

2、创建临时目录

cd /opt
mkdir nginx
cd nginx

3、下载安装包并解压

wget -c https://nginx.org/download/nginx-1.18.0.tar.gz
tar -zxvf nginx-1.18.0.tar.gz

4、进入解压目录

cd nginx-1.18.0

5、配置

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_sub_module --with-http_gzip_static_module --with-pcre --with-stream

6、编译安装

make && make install

7、此时已完成安装,安装目录

/usr/local/nginx

8、systemctl管理

1)进入系统目录

cd /usr/lib/systemd/system/

2)创建服务文件

touch nginx.service

3)编辑nginx.service,复制内容

vim nginx.service
[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true

[Install]
WantedBy=multi-user.target

4)重新加载服务配置

systemctl daemon-reload

5)启动

systemctl start nginx

## 启动可能失败,因为端口可能冲突

6)修改端口

cd /usr/local/nginx/conf/
vim nginx.conf

listen 80 -> listen 8081

或者其他端口

 7)重试启动

systemctl start nginx

8)完成

若还启动失败,请自行通过错误提示排查问题

 9)备份命令

## 停止ng服务
systemctl stop nginx

## 查看启动状态
systemctl status nginx

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值