[Nginx/Linux/CENTOS]安装Nginx

1 基本信息

服务器OS : Linux CENTSO 7.9
待安装的Nginx版本: NGINX 15.12

2 安装过程

step1 下载安装包

# cd /usr/local/software/
# wget http://nginx.org/download/nginx-1.15.12.tar.gz

step2 解压安装包

# cd /usr/local/software/
# tar -zxvf nginx-1.15.12.tar.gz -C ./

step3 安装依赖项

解决异常: ./configure时报的异常:
./configure: error: the HTTP rewrite module requires the PCRE library. ...
参考文献
安装nginx时候提示:./configure: error: the HTTP rewrite module requires the PCRE library. - CSDN

# yum -y install gcc gcc-c++ automake autoconf libtool make 
# yum -y install pcre-devel openssl openssl-devel

step4 配置与安装前检查

cd /usr/local/software/nginx-1.15.12

./configure --prefix=/usr/local/nginx 
--conf-path=/usr/local/nginx/conf 
--with-http_stub_status_module
  • ./configure --help
  • --prefix=PATH 设置软件安装目录路径
  • --with-http_stub_status_module 启用HTTP_Stub_Status模块,状态信息统计模块,用于返回一个Nginx状态信息统计信息页面。管理员访问这个页面可以获取Nginx的请求处理、当前连接、等待连接等统计信息,一般用于监控Nginx的运行状态。默认情况下不构建此模块。
  • --conf-path=PATH 设置配置文件安装目录路径

step5 编译

cd /usr/local/software/nginx-1.15.12
make

step6 安装

cd /usr/local/software/nginx-1.15.12
make install

step7 查验版本

/usr/local/nginx/sbin/nginx -V

step8 开启网内外部主机访问端口

  • 方法1 关闭防火墙

防火墙管理,可参见:

systemctl stop firewalld
 // service firewalld status
 // service iptables stop
  • 方法2 仅开启对应端口
systemctl start firewalld
firewall-cmd --permanent --add-port=80/tcp
systemctl restart firewalld

step9 查验运行状态

3 Nginx卸载

step1 全局查找Nginx相关文件

sudo find / -name nginx*
whereis nginx

step2 删除查找出来的所有Nginx相关文件

yum remove nginx
  // 先使用yum清理

sudo rm -rf <fileOrDir> 
  // 最后,依次手动删除查找出来的nginx文件(夹)

删除之后,便可重新安装nginx了。

X 参考文献

赞赏-支付宝二维码
本文作者千千寰宇
本文链接 https://www.cnblogs.com/johnnyzen
关于博文:评论和私信会在第一时间回复,或直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:若本文对您有帮助,可点击右下角推荐一下。您的鼓励、【赞赏】(左侧赞赏支付码)是博主技术写作的重要动力!
原文地址:https://www.cnblogs.com/johnnyzen/p/14888336.html