Nginx的安装部署和配置管理

本文详细介绍了Nginx的安装过程,包括通过yum安装和源码安装两种方式。在yum安装中,强调了配置yum源的重要性。在源码安装部分,详细列举了每个步骤,如安装编译环境、pcre、openssl-devel、zlib,以及创建nginx用户和安装服务。同时,提到了编译安装时创建软链接的必要性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、Nginx

1、Nginx是一个高性能的 HTTP 和 反向代理 服务,也是一个IMAP/POP3/SMTP服务。
2、Nginx是一款轻量级(对环境的依赖性比较小,可以在任何操作系统上运行的) web服务器/反向代理服务器及电子邮件代理服务器。其特点是:占有内存少,并发能力强。

二、yum安装

1、配置nginx的yum源

[root@mike ~]# cd /etc/yum.repos.d/
[root@mike yum.repos.d]# vim nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
[root@mike yum.repos.d]# yum -y install nginx
[root@mike yum.repos.d]# nginx -v  #查看版本号
nginx version: nginx/1.16.1
[root@mike yum.repos.d]# nginx -V #查看版本且查看详细加载模块
nginx version: nginx/1.16.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --group=nginx --user=nginx --sbin-path=/usr/local
/nginx/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/tmp/nginx/client_body --http-proxy-temp-path=/tmp/nginx/proxy --http-fastcgi-temp-path=/tmp/nginx/fastcgi --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre --with-http_realip_module --with-stream

关闭防火墙和selinux

[root@mike~]# getenforce 
Enforcing
[root@mike ~]# setenforce 0
[root@mike ~]# systemctl stop firewalld
[root@mike ~]# systemctl disable firewalld
[root@mike ~]# systemctl start nginx

在这里插入图片描述

三、源码安装

1、安装编译环境

[root@mike ~]# yum -y install gcc gcc-c++

2、安装pcre软件包(使nginx支持http rewrite模块)

[root@mike ~]# yum install -y pcre pcre-devel

3、安装openssl-devel(使nginx支持ssl)

[root@mike ~]# yum install -y openssl openssl-devel 

4、安装zlib

[root@mike ~]# yum install -y zlib zlib-devel

5、创建用户nginx

[root@mike ~]# useradd nginx

6、安装

[root@mike ~]# wget http://nginx.org/download/nginx-1.16.1.tar.gz
[root@mike ~]# tar xzf nginx-1.16.1.tar.gz -C /usr/local/
[root@mike ~]# cd /usr/local/nginx-1.16.1/
[root@localhost nginx-1.16.1]# ./configure --prefix=/usr/local/nginx --group=nginx --user=nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/tmp/nginx/client_body --http-proxy-temp-path=/tmp/nginx/proxy --http-fastcgi-temp-path=/tmp/nginx/fastcgi --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre --with-http_realip_module --with-stream
[root@mike nginx-1.16.1]# make && make install

7、通过nginx控制服务

1、编译安装的时候,需要进行软链接

[root@proxy-nginx ~]# ln -s /usr/loacl/nginx/sbin/nginx  /usr/local/sbin
nginx -c /path/nginx.conf  	     # 以特定目录下的配置文件启动nginx:
nginx -s reload            	 	 # 修改配置后重新加载生效
nginx -s stop  				 	 # 快速停止nginx
nginx -t    					 # 测试当前配置文件是否正确
nginx -t -c /path/to/nginx.conf  # 测试特定的nginx配置文件是否正确

其中nginx -t nginx -s reload比较常用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值