源码编译安装
下载安装包
进入官网下载:nginx: download
上传至虚拟机
新建一个目录用来存放nginx 相关文件
mkdir -p /usr/local/nginx
将下载好的压缩包上传到刚刚新建好的目录下并解压
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | [root@localhost ~] # mkdir -p /usr/local/nginx [root@localhost nginx] # ll total 1052 -rw-r--r-- 1 root root 1073948 Mar 29 17:53 nginx-1.22.1. tar .gz # 解压 tar -zxvf nginx-1.22.1. tar .gz [root@localhost nginx] # tar -zxvf nginx-1.22.1.tar.gz nginx-1.22.1/ nginx-1.22.1 /auto/ nginx-1.22.1 /conf/ nginx-1.22.1 /contrib/ nginx-1.22.1 /src/ nginx-1.22.1 /configure nginx-1.22.1 /LICENSE nginx-1.22.1 /README nginx-1.22.1 /html/ ············ |
安装编译环境
1 2 3 4 5 6 7 8 | # 安装gcc,源码编译依赖 gcc 环境 yum -y install gcc-c++ # 安装pcre,pcre是一个perl库,包括perl兼容的正则表达式库,nginx的http模块使用pcre来解析正则表达式,所以需要安装pcre库 yum install -y pcre pcre-devel # 安装zlib,zlib 库提供了很多种压缩和解压缩的方式,nginx 使用 zlib 对 http 包的内容进行 gzip yum install -y zlib zlib-devel # 安装OpenSSL库 yum install -y openssl openssl-devel |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | # 进入解压后的目录 [root@localhost ~] # cd /usr/local/nginx/ [root@localhost nginx] # ls nginx-1.22.1 nginx-1.22.1. tar .gz [root@localhost nginx] # cd nginx-1.22.1 [root@localhost nginx-1.22.1] # ll total 800 drwxr-xr-x 6 kaisa kaisa 326 Mar 29 17:55 auto -rw-r--r-- 1 kaisa kaisa 317399 Oct 19 16:02 CHANGES -rw-r--r-- 1 kaisa kaisa 485035 Oct 19 16:02 CHANGES.ru drwxr-xr-x 2 kaisa kaisa 168 Mar 29 17:55 conf -rwxr-xr-x 1 kaisa kaisa 2590 Oct 19 16:02 configure drwxr-xr-x 4 kaisa kaisa 72 Mar 29 17:55 contrib drwxr-xr-x 2 kaisa kaisa 40 Mar 29 17:55 html -rw-r--r-- 1 kaisa kaisa 1397 Oct 19 16:02 LICENSE drwxr-xr-x 2 kaisa kaisa 21 Mar 29 17:55 man -rw-r--r-- 1 kaisa kaisa 49 Oct 19 16:02 README drwxr-xr-x 9 kaisa kaisa 91 Mar 29 17:55 src |
1 2 3 4 5 6 7 | # 执行安装 . /configure make make install # 执行完后 输入 whereis nginx 检查是否安装成功,如果出现路径则安装成功 [root@localhost nginx-1.22.1] # whereis nginx nginx: /usr/local/nginx |
1 2 3 4 5 6 7 8 9 10 | # 启动nginx,需进入安装目录 [root@localhost ~] # cd /usr/local/nginx/ [root@localhost nginx] # ls conf html logs nginx-1.22.1 nginx-1.22.1. tar .gz sbin [root@localhost nginx] # ./sbin/nginx # 查看进程 [root@localhost nginx] # ps -ef | grep nginx root 6787 1 0 18:15 ? 00:00:00 nginx: master process . /sbin/nginx nobody 6788 6787 0 18:15 ? 00:00:00 nginx: worker process root 6790 1415 0 18:16 pts /1 00:00:00 grep --color=auto nginx |
浏览器查看访问 IP:80
nginx常用命令
1 2 3 4 5 6 7 8 9 10 | # 进入nginx的执行目录 cd /usr/local/nginx/sbin # 启动nginx . /nginx # 停止nginx(强制停止) . /nginx -s stop # 退出nginx(安全退出) . /nginx -s quit # 重新加载配置文件(修改过配置文件后使用) . /nginx -s reload |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | # 防火墙相关命令 # 关闭防火墙 systemctl stop firewalld # 开启防火墙 systemctl start firewalld # 查看防火墙状态 systemctl status firewalld # 查看防火墙规则 firewall-cmd --list-all # 查询端口是否开放 firewall-cmd --query-port=80 /tcp # 开放80端口 firewall-cmd --permanent --add-port=80 /tcp # 关闭80端口 firewall-cmd --permanent --remove-port=8080 /tcp # 重启防火墙(修改配置后要重启防火墙) firewall-cmd --reload |
复制