🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## 一、安装 ## **依赖** ``` yum -y install pcre-devel ``` ``` yum -y install openssl openssl-devel ``` ## **下载** ``` wget http://nginx.org/download/nginx-1.21.6.tar.gz ``` 然后解压下载的目录,进入解压目录中,在编译安装之前,需要安装两个依赖: ``` tar -zxvf nginx-1.21.6.tar.gz ``` 进入解压后的目录: ``` cd nginx-1.21.6 ``` ## **然后开始编译安装** 先创建目标目录: ``` mkdir -p /usr/lib/app/nginx ``` 然后正式安装: ``` 1. ./configure --prefix=/usr/lib/app/nginx 2. make 3. make install ``` ## **可能的问题** 安装中间,可能会出现要求安装其他第三方库的情况,那么,按照要求,安装就可以了,如;比如; 问题: ``` ./configure: error: the HTTP rewrite module requires the PCRE library. You can either disable the module by using --without-http_rewrite_module option, or install the PCRE library into the system, or build the PCRE library statically from the source with nginx by using --with-pcre=<path> option. ``` 解决办法: ``` yum install -y pcre pcre-devel ``` 问题: ``` ./configure: error: the HTTP gzip module requires the zlib library. You can either disable the module by using --without-http_gzip_module option, or install the zlib library into the system, or build the zlib library statically from the source with nginx by using --with-zlib=<path> option. ``` 解决办法: ``` yum install -y zlib zlib-devel ``` 问题: ``` ./configure: error: C compiler cc is not found ``` 解决办法: ``` yum -y install gcc-c++ ``` 然后,再重新执行中断的./configure ## **装好之后,安装位置在指定的地方,如果没有指定,默认有个安装位置** ``` /usr/local/nginx/ ``` ## 二、验证 进入到该目录的 sbin目录下,执行 nginx即可启动Nginx: ``` cd /usr/local/nginx/sbin ./nginx ``` ![](https://img.kancloud.cn/04/1f/041f1ecc303fe92fd0fada3095b415a1_260x72.png) Nginx 启动成功之后,在浏览器中直接访问了; >[danger] 如果不能访问,看看是不是防火墙的80端口没有打开; ## 三、卸载 停止Nginx软件 ``` nginx -s stop ``` 查找根下所有名字包含nginx的文件 ``` find / -name nginx ``` 执行命令 rm -rf *删除nignx安装的相关文件 ``` rm -rf ```