轻松上手:在Linux上安装Nginx的简明指南

Nginx,这一极为流行和功能强大的开源Web服务器和反向代理。无论您是开发人员、系统管理员还是IT爱好者,掌握如何安装和配置Nginx都将是您技能库中的一项宝贵资产。
Nginx以其高性能、稳定性和低资源消耗闻名,特别在处理大量并发连接时表现卓越。它是全球许多高流量网站的幕后英雄,无论是作为静态和动态内容的Web服务器,还是作为复杂网络结构的反向代理或负载均衡器,Nginx都能提供一流的性能。

通过本系列文章,我们将逐步引导您完成安装过程,确保您能够顺利启动并运行Nginx。让我们开始吧,打开您的Linux终端,一起踏上Nginx的安装之旅!


种一棵树最好的时间是10年前,其次就是现在,加油!
                                                                                   --by蜡笔小柯南

一、Nginx下载

  1. 进入 nginx官网,https://nginx.org/en/download.html,根据需要进行下载
    在这里插入图片描述

  2. 选择Linux版本,点击进行下载,下载完成后,得到压缩包
    在这里插入图片描述

二、Nginx安装

  1. 将下载好的压缩包,上传到Linux服务器,选择合适的位置进行上传

  2. 上传完成后,解压缩,使用以下命令

    tar -zxvf nginx-1.26.1.tar.gz
    
  3. 解压完成后,得到 nginx 目录
    在这里插入图片描述

  4. 进入此目录,执行 configure 文件
    在这里插入图片描述

    # 进入目录
    cd nginx-1.26.1
    # 执行
    ./configure
    
  5. 根据所提示的信息,安装所需要的依赖。安装好依赖后,再次执行configure文件,看是否还缺少依赖,如果缺少,进行对应的安装

a. 提示没有C编辑环境
./configure: error: C compiler cc is not fund
Ubuntu系统:
 sudo apt update
 sudo apt install build-essential
 sudo apt install g++
 # 还可以使用此命令进行修补安装,即已安装了部分build-essential,但没有安装完	全,此时可以使用该命令继续安装build-essential
 sudo apt install build-essential --fix-missing
CentOS系统:
 sudo yum install -y gcc
b. 提示如下信息,the HTTP rewrite module requires the PCRE library
 ./configure: error: the HTTP rewrite module requires the PCRE library.
 You can either disable the module by using --without-http_rewrite_module
 option, or install the PCRE library into the system, or build the PCRE library
 statically from the source with nginx by using --with-pcre=<path> option.
Ubuntu系统:
 sudo apt install libpcre3 libpcre3-dev
CentOS系统:
 sudo yum install -y pcre pcre-devel
c. 提示如下信息,the HTTP gzip module requires the zlib library
 ./configure: error: the HTTP gzip module requires the zlib library.
 You can either disable the module by using --without-http_gzip_module
 option, or install the zlib library into the system, or build the zlib library
 statically from the source with nginx by using --with-zlib=<path> option.
Ubuntu系统:
 sudo apt install zlib1g-dev
CentOS系统:
 sudo yum install -y zlib zlib-devel
  1. 安装完成后,再次运行 configure 文件,出现以下信息,说明依赖已经安装好
    Configuration summary
    + using system PCRE library
    + OpenSSL library is not used
    + using system zlib library
    
    nginx path prefix: "/usr/local/nginx"
    nginx binary file: "/usr/local/nginx/sbin/nginx"
    nginx modules path: "/usr/local/nginx/modules"
    nginx configuration prefix: "/usr/local/nginx/conf"
    nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
    nginx pid file: "/usr/local/nginx/logs/nginx.pid"
    nginx error log file: "/usr/local/nginx/logs/error.log"
    nginx http access log file: "/usr/local/nginx/logs/access.log"
    nginx http client request body temporary files: "client_body_temp"
    nginx http proxy temporary files: "proxy_temp"
    nginx http fastcgi temporary files: "fastcgi_temp"
    nginx http uwsgi temporary files: "uwsgi_temp"
    nginx http scgi temporary files: "scgi_temp"
    
  2. 在nginx目录下,执行 make 命令和 make install 命令
    make
    
    make install
    
  3. 执行完成后,在 /usr/local 目录下,可以看到我们安装的nginx目录
    在这里插入图片描述
    使用以下命令,查看
	# 进入usr/local目录
	cd /usr/local

	# 查看目录列表
	ls

三、Nginx启动与停止

  1. Nginx启动,进入 /usr/local/nginx/sbin 目录,执行启动文件

    # 进入nginx的sbin目录
    cd /usr/local/nginx/sbin
    
    # 执行
    ./nginx
    
  2. 查看是否启动成功,在Linux目录窗口,输入:crul ip地址

    curl 自己服务器的ip地址
    

    出现以下信息则代表启动成功
    在这里插入图片描述
    如果通过浏览器访问,打不开欢迎页面,检测服务器的安全组是否打开了相应端口,以及防火墙设置

  3. Nginx停止

    ./nginx -s stop
    
    ./nginx -s quit
    
    
  4. Nginx重新加载命令

    ./nginx -s reload
    

🆗,Linux中,Nginx安装完成,完结散花!!!



如果你有任何疑问或经验分享,可以在评论区留言哦~~

不管在任何时候,我希望你永远不要害怕挑战,不要畏惧失败。每一个错误都是向成功迈出的一步,每一个挑战都是成长的机会,因为每一次的努力,都会使我们离梦想更近一点。只要你行动起来,任何时候都不算晚。最后,把座右铭送给大家:种一棵树最好的时间是10年前,其次就是现在,加油!共勉 💪。
获取Java资料,以及八股文信息,快来吧 👇👇👇

不论是Java的基础资料,还是那些看似枯燥实则精妙的八股文,这里都有你意想不到的解读方式,让复杂变简单,让枯燥变有趣~

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值