安装nginx
yum安装nginx
安装前需要安装epel源,使用yum安装nginx即可。
源码安装nginx
源码包: 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服务 |