当前位置: 首页 > article >正文

2. 在Linux 当中安装 Nginx(13步) 下载安装启动(详细说明+附加详细截图说明)

2. 在Linux 当中安装 Nginx(13步) 下载&安装&启动(详细说明+附加详细截图说明)

文章目录

  • 2. 在Linux 当中安装 Nginx(13步) 下载&安装&启动(详细说明+附加详细截图说明)
  • 1. 在 Linxu 下安装 Nginx 的详细步骤
  • 2. 最后:


1. 在 Linxu 下安装 Nginx 的详细步骤

Nginx 官方下载地址:https://nginx.org/en/download.html
在这里插入图片描述

注意:保证Linux 虚拟机可以访问到外网:

[root@localhost bin]# ping www.baidu.com

在这里插入图片描述

具体的安装步骤如下:

  1. 搭建 gcc 环境
yum -y install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel

特别的:

  1. 一定要保证当前的 linux 系统, 可以连接外网, 因为 yum 需要到外网,获取数据
  2. 如 何 在 Linux 配 置 网 络 , 可 以 连 接 到 外 网 , 大家可以移步至:韩老师的教学https://www.bilibili.com/video/BV1Sv411r7vd?p=63
  3. 执行上面指令的时候, 可能会报 Centos Another app is currently holding the yum lock..错误, 是因为 yum 不时会自动升级, 占用了端口或文件, 解决方案 :
    1. 可以重启 Linux, 立即执行该指令
    2. 或 者等一会再执行
    3. 或者参考 https://www.cnblogs.com/lzxianren/p/4254059.html

在这里插入图片描述

可以执行如下指令:查看 gcc 安装的版本信息:

[root@localhost bin]# gcc --version
或者
[root@localhost bin]# gcc -v

在这里插入图片描述

安装 gcc 提示一些镜像失败的问题:yum 安装软件提示 cannot find a valid baseurl for repo:base/7/x86_64 的解决方法(2024更新),大家可以移步至:🌟🌟🌟 [Linux 用yum安装软件提示 cannot find a valid baseurl for repo:base/7/x86_64 的解决方法(2024更新)-CSDN博客](Linux 用yum安装软件提示 cannot find a valid baseurl for repo:base/7/x86_64 的解决方法(2024更新)-CSDN博客) 尝试解决,亲测有效。

  1. 通过 Xftp 将 nginx-1.20.2.tar.gz 上传到 Linux /opt 目录当中

一般,在 Linux 当中都是将安装软件放到 opt 目录下

在这里插入图片描述

在这里插入图片描述

进入到 opt 目录当中查看,是否上传成功。

[root@localhost opt]# cd /opt

在这里插入图片描述

  1. 切换到 /opt 目录 将上传的 nginx-1.20.2.tar.gz 文件解压
[root@localhost opt]# tar -zxvf nginx-1.20.2.tar.gz 

在这里插入图片描述

在这里插入图片描述

4. 将解压后的文件放到指定位置/usr/local/nginx 文件目录当中

[root@localhost opt]# mv nginx-1.20.2 /usr/local/nginx

在这里插入图片描述

5. 进入到 /usr/local/nginx文件目录当中

[root@localhost opt]# cd /usr/local/nginx

在这里插入图片描述

6. 配置 nginx 路径

注意:一定要进入到 nginx 目录当中去,才行。因为只有在 nginx 目录下,才有这个我们编排的 :configure 文件夹。才能执行如下指令。

在这里插入图片描述

./configure
--prefix=/usr/local/nginx
--pid-path=/var/run/nginx/nginx.pid
--lock-path=/var/lock/nginx.lock
--error-log-path=/var/log/nginx/error.log
--http-log-path=/var/log/nginx/access.log
--with-http_gzip_static_module
--http-client-body-temp-path=/var/temp/nginx/client
--http-proxy-te
mp-path=/var/temp/nginx/proxy
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi
--http-scgi-temp-path=/var/temp/nginx/scgi
--conf-path=/usr/local/nginx/nginx.conf

在这里插入图片描述

在这里插入图片描述

7. 补全 nginx 配置目录

执行如下命令

mkdir /var/temp/nginx -p

在这里插入图片描述

8. 编译并安装

执行如下命令:

make && make install

在这里插入图片描述

执行:

yum -y install make zlib-devel gcc-c++ libtool openssl openssl-devel

在这里插入图片描述

重新configure,执行下边命令:

./configure --user=nobody --group=nobody --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_sub_module --with-http_ssl_module

重新编译,执行下边命令:

make && make install

如果还是安装失败的:可以看看这篇文章https://blog.csdn.net/y2020520/article/details/131187585

9. 测试配置与 nginx 是否正常,当出现 successful 即可

[root@localhost nginx]# ./sbin/nginx -t

在这里插入图片描述

在这里插入图片描述

10. 启动 nginx

./sbin/nginx -c # 启动Nginx 
./sbin/nginx -c nginx.conf # 启动 Nginx ,同时指明是通过哪个路径下的 nginx.conf 配置文件进行启动,不写明,则是启动 /usr/local/nginx/conif 默认路径下面的 nginx.conf 进行启动 nginx 的
# 注意:这里我们是在 Nginx 目录下其启动的,所以用的是:./sbin
绝对路径进行启动的方式:
/usr/local/nginx/sbin/nginx -c

在这里插入图片描述

启动 Nginx 可能的错误 和解决方案

解决 nginx 启动报错 nginx: [emerg] open() "/var/run/nginx/nginx.pid" failed (2: No such file or directory)

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

pid       /usr/local/nginx/logs/nginx.pid;
[root@localhost conf]# mkdir /usr/local/nginx/log

11. 查看进程/或端口(默认端口是 80)

[root@localhost nginx]# ps -ef | grep nginx
root       2477      1  0 20:07 ?        00:00:00 nginx: master process ./sbin/nginx
nobody     2488   2477  0 20:08 ?        00:00:00 nginx: worker process
root       2519   2417  0 20:10 pts/0    00:00:00 grep --color=auto nginx

在这里插入图片描述

注意:养成一个好习惯,每次启动任何服务器,都执行一下 ps -ef | grep xxx 查看该服务器是否启动成功了。

12. 验证Nginx 是否安装成功

nginx 默认监听端口 80,出现 Welcome to nginx!该页面就是搞定了

Linux 的浏览器:http://localhost

在这里插入图片描述

13. 配置防火墙,让 Windows 访问 Nginx

说明:默认情况下 Windows 是不能访问 Nginx , 因为Linux虚拟机是当中防火墙是关闭 80 端口的,关闭了,外界是无法访问到 80端口的。所以我们需要将其打开,让外界我们的 windows 可以访问到 80 端口。

查看开放的端口号

[root@localhost nginx]# firewall-cmd --list-all

在这里插入图片描述

设置开放的端口号

#firewall-cmd --add-service=http --permanent #增加了一个 http 服务,理解
firewall-cmd --add-port=80/tcp --permanent

重启防火墙,只有重启了防火墙,你对防火墙的配置才会生效

firewall-cmd --reload

重启后,再次执行,查看防火墙开放的端口信息:

[root@localhost nginx]# firewall-cmd --list-all

在这里插入图片描述

测试: windows 浏览器上输入:[Linux ifconfig 查看到的IP地址]+80端口 : http://192.168.12.134/

在这里插入图片描述

补充:

查看 Nginx 的版本信息指令:

[root@localhost nginx]# ./sbin/nginx -v

在这里插入图片描述

重启 Nginx的指令:该指令也是在 Nginx 安装目录下执行的。

[root@localhost nginx]# ./sbin/nginx -s reload

2. 最后:

“在这个最后的篇章中,我要表达我对每一位读者的感激之情。你们的关注和回复是我创作的动力源泉,我从你们身上吸取了无尽的灵感与勇气。我会将你们的鼓励留在心底,继续在其他的领域奋斗。感谢你们,我们总会在某个时刻再次相遇。”

在这里插入图片描述


http://www.kler.cn/a/562807.html

相关文章:

  • qt-C++笔记之QtCreator新建项目即Create Project所提供模板的逐个尝试
  • 【FastGPT】Linux系统使用podman-compose方式部署指南
  • web安全——分析应用程序
  • 山东大学软件学院ai导论实验之生成对抗网络
  • Qt 自定义控件及插件使用浅谈
  • Java 大视界 -- Java 大数据分布式文件系统的性能调优实战(101)
  • 人工智能中的特征是什么?
  • 腾讯 DeepSeek-R1 × Vue3 使用体验报告
  • SQLite 安装教程以及可视化工具介绍
  • 爬虫获取 t_nlp_word 文本语言词法分析接口:技术实现与应用实践
  • Web漏洞——命令注入漏洞学习
  • 数据存储:使用Python存储数据到redis详解
  • 用于训练基于pytorch构建的小型字符级语言模型的数据集汇总
  • 「宇树科技」13家核心零部件供应商梳理!
  • 无监督学习——聚类问题:K-Means聚类算法详解
  • xenomai4的dovetail学习(2)——oob和中断管理
  • 清华deepseek文档下载地址,DeepSeek:如何赋能职场应(附下载包)64页全面详细介绍(二)
  • SQL注入练习
  • ChatVLA:基于视觉-语言-动作模型的统一多模态理解和机器人控制
  • 用Python3脚本实现Excel数据到TXT文件的智能转换:自动化办公新姿势