nginx的安装

本文介绍了在Linux系统中通过yum和源码两种方式安装Nginx的详细过程,包括安装依赖、配置、编译及启动管理命令。同时,提供了启动失败时的排错思路,如检查防火墙和80端口状态,并展示了Nginx相关文件路径及常用命令。
摘要由CSDN通过智能技术生成

安装nginx

yum安装nginx

安装前需要安装epel源,使用yum安装nginx即可。
yum下载epel源

源码安装nginx

官网: http://nginx.org/

源码包: nginx-1.20.1.tar.gz

源码包下载: wget http://nginx.org/download/nginx-1.20.1.tar.gz -P /usr/src
1.安装nginx
安装依赖包:gcc pcre-devel zlib-devel

  • gcc: 源码编译工具
  • pcre-devel: nginx url_rewrite 功能提供包
  • zlib-devel: nginx 压缩功能提供包

2.解压源码包,并进入源码包中

[root@localhost ~]# tar xf nginx-1.20.1.tar.gz   #解压tar包
[root@localhost ~]# cd nginx-1.20.1    ##切入目录

3.配置nginx,并编译安装
[root@localhost nginx-1.20.1]# mkdir /usr/local/nginx
[root@localhost nginx-1.20.1]# ./configure --prefix=/usr/local/nginx
配置目的:
1)检查环境 是否 满足安装条件 依赖解决
2)指定安装方式 配置文件 命令文件 各种文件放哪里 开启模块功能【内置模块 三方模块】
3)指定软件安装在那里

 ## 编译安装
[root@localhost ~]# make && make install
nginx链接到放到sbin下
[root@localhost ~]# ln -s /usr/local/nginx/sbin/nginx  /usr/sbin/

源码吗启动nginx
启动nginx
[root@localhost ~]# nignx
重新加载nginx
[root@localhost ~]# nginx -s reload
停止nginx
[root@localhost ~]# nginx -s stop
yum安装启动ngin
[root@localhost ~]# setenforce 0            ##开启宽容模式--关闭seliunx
[root@localhost ~]# systemctl stop firewalld  ##关闭防火墙
[root@localhost ~]# nginx -t                  ##测试nginx是否正常启动
[root@localhost ~]# systemctl start nginx     ##开启nginx服务
[root@localhost ~]# systemctl enable nginx    ##加入开机自启
######################################################################
[root@localhost ~]# systemctl stop nginx      ##停止服务运行
[root@localhost ~]# systemctl disable nginx   ##取消开机自启

百度输入虚拟主机IP访问,查看是否为启动,访问成功如下图。在这里插入图片描述

nginx相关文件

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”

排错思路

启动失败时,查看防火墙是否关闭,或者查看80端口是否开启。

[root@localhost ~]# ss -lnt         ##查看主机80端口
State      Recv-Q Send-Q       Local Address:Port                      Peer Address:Port              
LISTEN     0      128              127.0.0.1:6379                                 *:*                  
LISTEN     0      128                      *:80                                   *:*                  
LISTEN     0      128                      *:22                                   *:*                
[root@localhost ~]# netstat -lnt     ##查看主机80端口
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     

[root@localhost ~]# ps -aux | grep nginx      ##查看进程nginx是否开启  
root      13421  0.0  0.0  39304   936 ?        Ss   05:58   0:00 nginx: master process /usr/sbin/nginx
nginx     13422  0.0  0.2  39696  2056 ?        S    05:58   0:00 nginx: worker process
root      14212  0.0  0.0 112816   964 pts/0    S+   06:13   0:00 grep --color=auto nginx

nginx常用命令

命令解析
nginx开启nginx
nginx -v查看版本号
nginx -s stop关闭nginx
nginx -s reload重新加载nginx服务
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值