好网站建设公司北京,天津电力建设公司网站,特效视频制作软件app,湖北长安建设集团官方网站优质博文#xff1a;IT-BLOG-CN 一、安装Nginx
【1】首先通过Nginx官网确定需要安装的版本#xff0c;如果Linux联网则直接在Linux服务上使用wget命令将Nginx安装包下载到/usr/local/目录下#xff1a;
[rootxxx local]# wget -c http://nginx.org/download/nginx-1.22.1.… 优质博文IT-BLOG-CN 一、安装Nginx
【1】首先通过Nginx官网确定需要安装的版本如果Linux联网则直接在Linux服务上使用wget命令将Nginx安装包下载到/usr/local/目录下
[rootxxx local]# wget -c http://nginx.org/download/nginx-1.22.1.tar.gz
--2024-02-20 10:52:39-- http://nginx.org/download/nginx-1.22.1.tar.gz
Resolving nginx.org (nginx.org)... 52.58.199.22, 3.125.197.172, 2a05:d014:5c0:2600::6, ...
Connecting to nginx.org (nginx.org)|52.58.199.22|:80... connected.
HTTP request sent, awaiting response... 416 Requested Range Not SatisfiableThe file is already fully retrieved; nothing to do.如果是未Linux未联网可以手动下载后将压缩包上传至/usr/local/目录下。如果没有wget命令通过yum install -y wget命令安装即可。 【2】安装Nginx依赖包gcc、PCRE pcre-devel、zlib、OpenSSL可以通过如下命令在线安装
[rootxxx local]# yum install -y gcc-czlib zlib-developenssl openssl-devel pcre pcre-devel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
base | 3.6 kB 00:00:00
https://download.docker.com/linux/centos/7/x86_64/stable/repodata/repomd.xml: [Errno 14] curl#77 - Problem with the SSL CA cert (path? access rights?)
Trying other mirror.
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/3): epel/x86_64/updateinfo | 1.0 MB 00:00:00
(2/3): epel/x86_64/primary_db | 7.0 MB 00:00:00
(3/3): updates/7/x86_64/primary_db 安装nginx需要先将官网下载的源码进行编译编译依赖gcc环境。 PCRE(Perl Compatible Regular Expressions)是一个Perl库包括perl兼容的正则表达式库。nginx的http模块使用pcre来解析正则表达式所以需要在linux上安装pcre库pcre-devel是使用pcre开发的一个二次开发库。nginx也需要此库。 zlib库提供了很多种压缩和解压缩的方式nginx使用zlib对http包的内容进行gzip所以需要在Centos上安装zlib库。OpenSSL是一个强大的安全套接字层密码库囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议并提供丰富的应用程序供测试或其它目的使用。nginx不仅支持http协议还支持https即在ssl协议上传输http所以需要在Centos安装OpenSSL。 离线安装 【Linux可联网时忽略即可】
离线安装依赖包解压后使用rpm -Uvh *.rpm --nodeps --force命令安装
[rootxxx local]# rpm -Uvh *.rpm --nodeps --force【3】安装Nginx解压Nginx安装包进入解压后的目录nginx-1.22.1。执行./configure命令。注意如果需要安装SSL认证需要执行./configure --prefix/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module命令。configure脚本的作用就是生成Makefile文件。这个脚本可以带一些参数用于控制程序的编译行为。通过执行configure --help来查看完整的命令参数。
[rootxxx nginx]# ./configure 【4】编译执行make进行编译编译后才能进行安装
[rootxxx nginx]# make【5】安装执行make install进行安装安装后可以看到多了一个名为sbin的文件夹
[rootxxx nginx]# make install【6】启动Nginx进入sbin文件夹执行./nginx启动nginx
[rootxxx sbin]# ./nginx【7】Nginx默认为80端口启动后可以在浏览器输入自己的ip和端口号进行验证是否启动成功 【8】环境变量配置编辑/etc/profile文件在最后一行添加如下信息
PATH$PATH:/usr/local/nginx/sbin刷新/etc/profile
source /etc/profile【9】查看nginx版本
[rootxxx sbin]# nginx -v
nginx version: nginx/1.22.1【10】暴力停止服务
[rootxxx sbin]# nginx -s stop【12】优雅停止服务
[rootxxx sbin]# nginx -s quit【13】检查配置文件
[rootxxx sbin]# nginx -t【14】重新加载配置
[rootxxx sbin]# nginx -s reload卸载Nginx
方案一使用apt命令卸载nginx 【1】停止Nginx服务。使用命令sudo systemctl stop nginx来停止Nginx服务确保Nginx不再在运行中。 【2】确认Nginx服务是否已停止。使用命令sudo systemctl status nginx来确认Nginx服务是否已停止如果显示Active: inactive则表示Nginx已停止。 【3】卸载Nginx软件包。使用命令sudo apt remove nginx来卸载Nginx及其相关的依赖软件包。 【4】删除Nginx配置文件和日志文件。使用命令sudo rm -rf /etc/nginx /var/log/nginx来删除Nginx的配置文件和日志文件。 【5】清理可能残留的Nginx文件。使用命令sudo apt autoremove来自动删除不再需要的软件包和依赖项。 【6】验证Nginx是否已完全卸载。使用命令which nginx来验证Nginx是否已成功卸载如果没有任何输出表示Nginx已成功卸载。
方案二使用源码安装的方式卸载nginx 【1】如果我们是通过源码安装的方式安装的nginx那么卸载它就需要一些额外的步骤。首先我们需要找到nginx的安装目录一般来说它是在/usr/local/nginx下面。然后我们可以执行以下命令
[rootxxx sbin]# sudo make uninstall【2】这个命令会删除nginx的程序文件和配置文件但是不会删除nginx的日志文件和缓存文件。如果我们想要完全删除nginx的所有文件可以使用以下命令
[rootxxx sbin]# sudo rm -rf /usr/local/nginx【3】这个命令会删除nginx的所有文件和目录包括日志文件和缓存文件。这个命令会删除一些可能有用的数据所以在执行之前请做好备份。