• Install Nginx in Linux


    Nginx是一款轻量级的Web服务器、反向代理服务器,由于它的内存占用少,启动极快,高并发能力强,在互联网项目中广泛应用。

    1.yum 安装 nginx

    1. [root@VM-8-7-centos nginx]# yum install -y nginx
    2. Loaded plugins: fastestmirror, langpacks
    3. Repository epel is listed more than once in the configuration
    4. Loading mirror speeds from cached hostfile
    5. No package nginx available.
    6. Error: Nothing to do

    参考了一些方法:

    -通过 epel-release 额外软件包 

    1. yum install epel-release
    2. yum clean all
    3. yum makecache
    4. yum install nginx -y

    - 通过新增yum 源

    1. vi /etc/yum.repos.d/nginx.repo
    2. [nginx]
    3. name=nginx repo
    4. baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
    5. gpgcheck=0
    6. enabled=1

    都没有成功 o(╥﹏╥)o

    2.手动安装

    安装依赖项
    在开始安装Nginx之前,首先需要安装一些依赖项,以确保Nginx编译和运行正常。打开终端并执行以下命令:

     2.1 安装必要的工具和库,以支持Nginx的编译和运行
    yum install -y wget gcc-c++ pcre-devel zlib-devel openssl-devel
    2.2 下载Nginx 并解压

    从Nginx官网下载最新的稳定版本。下载链接https://nginx.org/en/download.html

    1. # 例如,下载Nginx 1.21.0版本
    2. wget https://nginx.org/download/nginx-1.21.0.tar.gz
    3. # 并解压
    4. tar -zxvf nginx-1.21.0.tar.gz
    2.3 编译和安装
    1. cd nginx-1.24.0
    2. # 编译前的配置和依赖检查
    3. ./configure
    4. # 编译安装
    5. make && make install

    Nginx安装完成后,默认自动创建 /usr/local/nginx 目录,并创建必要的文件和目录,包括配置文件、日志文件、HTML文件等。

    2.4  防火墙设置

    如果您的系统启用了防火墙,需要关闭防火墙

    1. # 查看防火墙状态
    2. systemctl status firewalld
    3. # 关闭防火墙
    4. systemctl stop firewalld
    5. # 开机禁用防火墙
    6. systemctl disable firewalld

    3. 启动Nginx

    3.1 手动启动 与 关闭
    1. # 进入Nginx的安装目录:
    2. cd /usr/local/nginx/sbin
    3. # 启动Nginx服务器:
    4. ./nginx

    启动后 通过浏览器访问您的服务器的IP地址或域名, 如下则来验证Nginx已正常工作。

     

    1. # 关闭
    2. /usr/local/nginx/sbin/nginx -s stop
    3.2 配置 Nginx 为系统服务

    将 Nginx 制作成系统服务让你无需手动到 Nginx 安装目录下执行命令来启动它,而是系统会在开机时自动启动 Nginx,让启动过程更加方便和自动化。

    配置 Nginx 服务文件
    在 /etc/systemd/system/ 目录下创建一个新的服务文件,例如 nginx.service:

    vi /etc/systemd/system/nginx.service

    在打开的文件中,添加以下内容:

    1. [Unit]
    2. Description=Nginx HTTP Server
    3. After=network.target
    4. [Service]
    5. Type=forking
    6. ExecStart=/usr/local/nginx/sbin/nginx
    7. ExecReload=/usr/local/nginx/sbin/nginx -s reload
    8. ExecStop=/usr/local/nginx/sbin/nginx -s stop
    9. PrivateTmp=true
    10. [Install]
    11. WantedBy=multi-user.target

    执行以下命令重新加载 systemd 配置文件:

    systemctl daemon-reload

    执行以下命令启动 Nginx 服务:

    systemctl start nginx

    现在,Nginx 将作为系统服务在后台运行。

    3.3 设置开机自启动
    1. # 开机自启动
    2. systemctl enable nginx
    3. # 检查 Nginx 状态
    4. systemctl status nginx
    5. # 停止 Nginx 服务
    6. systemctl stop nginx
    7. # 重启 Nginx 服务
    8. systemctl restart nginx
    3.4 卸载 Nginx

    如果需要卸载Nginx,您可以执行以下步骤:

    1. # 停止 Nginx 服务:
    2. systemctl stop nginx
    3. # 确定Nginx的安装位置:
    4. whereis nginx
    5. # 删除Nginx安装目录:
    6. rm -rf /usr/local/nginx
    7. # 查找并删除相关文件:
    8. find / -name nginx

    这将搜索文件系统中所有包含 “nginx” 的文件名,并且你可以根据需要删除这些文件。

    完成以上步骤后,Nginx将被完全卸载。
     

  • 相关阅读:
    如何让 Xcode 在运行时问题(表示为紫色的小三角形)被发现时就立即中断以供调试
    快速串联 RNN / LSTM / Attention / transformer / BERT / GPT(未完待续)
    ssm+vue基本微信小程序的新冠疫苗预约小程序#毕业设计
    为什么说企业需要实施知识管理?
    Mybatis框架_涉及技术与拓展
    html&css
    Java多态之动态绑定机制
    刀片式服务器介绍
    重新整理汇编—————汇编的基础理论前置篇
    6.2 Restful
  • 原文地址:https://blog.csdn.net/qq_44376306/article/details/134354768