nginx安装部署和配置管理

nginx介绍

在这里插入图片描述
Nginx(engine x) 是一个高性能的 HTTP 和 反向代理 服务,也是一个IMAP/POP3/SMTP服务。Nginx是由伊戈尔·赛索耶夫为俄罗斯访问量第二的Rambler.ru站点(俄文:Рамблер)开发的,第一个公开版本0.1.0发布于2004年10月4日。其将源代码以类BSD许可证的形式发布,因它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名。2011年6月1日,nginx 1.0.4发布。

Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行。其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好,中国大陆使用nginx网站用户有:百度、京东、新浪、网易、腾讯、淘宝等。

在高连接并发的情况下,Nginx是Apache服务器不错的替代品。

创始人伊戈尔·赛索耶夫

在这里插入图片描述

为什么选择 nginx

Nginx 是一个高性能的 Web 和反向代理服务器, 它具有有很多非常优越的特性:

作为 Web 服务器: 相比 Apache,Nginx 使用更少的资源,支持更多的并发连接,体现更高的效率,这点使Nginx尤其受到虚拟主机提供商的欢迎。能够支持高达 50,000 个并发连接数的响应,感谢 Nginx 为我们选择了epoll and kqueue 作为开发模型.

作为负载均衡服务器: Nginx 既可以在内部直接支持 Rails 和 PHP,也可以支持作为HTTP代理服务器对外进行服务。Nginx 用 C 编写, 不论是系统资源开销还是 CPU 使用效率都比 Perlbal 要好的多。

作为邮件代理服务器: Nginx 同时也是一个非常优秀的邮件代理服务器(最早开发这个产品的目的之一也是作为邮件代理服务器),Last.fm 描述了成功并且美妙的使用经验。

Nginx 安装非常的简单,配置文件 非常简洁(还能够支持perl语法),Bugs非常少的服务器: Nginx 启动特别容易,并且几乎可以做到7*24不间断运行,即使运行数个月也不需要重新启动。你还能够在不间断服务的情况下进行软件版本的升级。

IO多路复用

1、I/O multiplexing【多并发】

第一种方法就是传统的多进程并发模型 (每进来一个新的I/O流会分配一个新的进程管理。)

第二种方法就是I/O多路复用 (单个线程,通过记录跟踪每个I/O流(sock)的状态,来同时管理多个I/O流 。)
在这里插入图片描述
I/O multiplexing 这里面的 multiplexing 指的其实是在单个线程通过记录跟踪每一个Sock(I/O流)的状态来同时管理多个I/O流。发明它的原因,是尽量多的提高服务器的吞吐能力。

在同一个线程里面, 通过拨开关的方式,来同时传输多个I/O流
在这里插入图片描述

2、一个请求到来了,nginx使用epoll接收请求的过程是怎样的?

ngnix会有很多连接进来, epoll会把他们都监视起来,然后像拨开关一样,谁有数据就拨向谁,然后调用相应的代码处理。

  • select, poll, epoll 都是I/O多路复用的具体的实现,其实是他们出现是有先后顺序的。I/O多路路复用这个概念被提出来以后, 相继出现了多个方案
  • select 是第一个实现 (1983 左右在BSD里面实现的)。
    select 被实现以后,很快就暴露出了很多问题。
    · select 会修改传入的参数数组,这个对于一个需要调用很多次的函数,是非常不友好的。
    · select 如果任何一个sock(I/O stream)出现了数据,select 仅仅会返回,但是并不会告诉你是哪个sock上有数据,于是你只能自己一个一个的找,10几个sock可能还好,要是几万的sock每次都找一遍…
    · select 只能监视1024个链接。
    · select 不是线程安全的,如果你把一个sock加入到select, 然后突然另外一个线程发现,这个sock不用,要收回,这个select 不支持的,如果你丧心病狂的竟然关掉这个sock, select的标准行为是不可预测的
  • 于是14年以后(1997年)一帮人又实现了poll, poll 修复了select的很多问题,比如
    · poll 去掉了1024个链接的限制,于是要多少链接呢, 主人你开心就好。
    · poll 从设计上来说,不再修改传入数组,不过这个要看你的平台了,所以行走江湖,还是小心为妙。其实拖14年那么久也不是效率问题, 而是那个时代的硬件实在太弱,一台服务器处理1千多个链接简直就是神一样的存在了,select很长段时间已经满足需求。
    但是poll仍然不是线程安全的, 这就意味着,不管服务器有多强悍,你也只能在一个线程里面处理一组I/O流。
    你当然可以那多进程来配合了,不过然后你就有了多进程的各种问题。
  • 于是5年以后, 在2002, 大神 Davide Libenzi 实现了epoll.
    epoll 可以说是I/O 多路复用新的一个实现,epoll 修复了poll 和select绝大部分问题, 比如:
    · epoll 现在是线程安全的。
    · epoll 现在不仅告诉你sock组里面数据,还会告诉你具体哪个sock有数据,你不用自己去找了。
3、异步,非阻塞

$ pstree |grep nginx |-+= 81666 root nginx: master process nginx | |— 82500 nobody nginx: worker process | — 82501 nobody nginx: worker process

1个master进程,2个work进程

每进来一个request,会有一个worker进程去处理。但不是全程的处理,处理到什么程度呢?处理到可能发生阻塞的地方,比如向上游(后端)服务器转发request,并等待请求返回。那么,这个处理的worker不会这么一直等着,他会在发送完请求后,注册一个事件:"如果upstream"返回了,告诉我一声,我再接着干”。 于是他就休息去了。这就是异步。此时,如果再有request 进来,他就可以很快再按这种方式处理。这就是非阻塞和IO多路复用。而一旦上游服务器返回了,就会触发这个事件,worker才会来接手,这个request才会接着往下走。这就是异步回调。

4、nginx 的内部技术架构

Nginx服务器,以其处理网络请求的高并发、高性能及高效率,获得了行业界的广泛认可,近年已稳居web服务器部署排名第二的位置,并被广泛用于反向代理和负载均衡。

Nginx是如何实现这些目标的呢?答案就是其独特的内部技术架构设计。看懂下面这张图,就明白了Nginx的内部技术架构。
在这里插入图片描述
简要说明几点:

1)nginx启动时,会生成两种类型的进程,一个是主进程(Master),一个(windows版本的目前只有一个)或多个工作进程(Worker)。主进程并不处理网络请求,主要负责调度工作进程,也就是图示的三项:加载配置、启动工作进程及非停升级。所以,nginx启动以后,查看操作系统的进程列表,我们就能看到至少有两个nginx进程。

2)服务器实际处理网络请求及响应的是工作进程(worker),在类unix系统上,nginx可以配置多个worker,而每个worker进程都可以同时处理数以千计的网络请求。

3)模块化设计。nginx的worker,包括核心和功能性模块,核心模块负责维持一个运行循环(run-loop),执行网络请求处理的不同阶段的模块功能,如网络读写、存储读写、内容传输、外出过滤,以及将请求发往上游服务器等。而其代码的模块化设计,也使得我们可以根据需要对功能模块进行适当的选择和修改,编译成具有特定功能的服务器。

4)事件驱动、异步及非阻塞,可以说是nginx得以获得高并发、高性能的关键因素,同时也得益于Linux、Solaris及类BSD等操作系统内核中事件通知及I/O性能增强功能的采用,如kqueue、epoll及event ports。

5)代理(proxy)设计,可以说是nginx深入骨髓的设计,无论是对于HTTP,还是对于FastCGI、memcache、Redis等的网络请求或响应,本质上都采用了代理机制。所以,nginx天生就是高性能的代理服务器

nginx安装部署和配置管理


1、nginx部署-Yum安装

访问nginx的官方网站:http://www.nginx.org/

Nginx版本类型

Mainline version: 主线版,即开发版
Stable version: 新稳定版,生产环境上建议使用的版本
Legacy versions: 遗留的老版本的稳定版
在这里插入图片描述
Yum安装nginx

配置Yum源的官网:http://nginx.org/en/linux_packages.html

1、配置nginx的Yum源

Installation instructions

Before you install nginx for the first time on a new machine, you need to set up the nginx packages repository. Afterward, you can install and update nginx from the repository.

安装说明

在新计算机上首次安装nginx之前,需要设置nginx软件包存储库。 之后,您可以从存储库安装和更新nginx.

RHEL/CENTOS

Install the prerequisites:

sudo yum install yum-utils -y

To set up the yum repository, create the file named /etc/yum.repos.d/nginx.repo with the following contents:

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=http://nginx.org/keys/nginx_signing.key

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key

By default, the repository for stable nginx packages is used. If you would like to use mainline nginx packages, run the following command:

sudo yum-config-manager --enable  nginx-mainline

To install nginx, run the following command:

sudo yum install nginx -y

When prompted to accept the GPG key, verify that the fingerprint matches 573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62 , and if so, accept it.

当提示您接受GPG密钥时,请验证指纹是否匹配 573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62 ,如果匹配,请接受它。

这里我们用稳定版本

[root@nginx-server yum.repos.d]# yum install -y nginx 
[root@nginx-server yum.repos.d]# nginx -V //格式化打印 nginx version: nginx/1.16.0 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log -http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock--path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module -with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --withhttp_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --withhttp_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,z,now -pie' 
[root@nginx-server yum.repos.d]# nginx -v nginx version: nginx/1.16.0

关闭防火墙和selinux:

[root@nginx-server ~]# getenforce Enforcing
[root@nginx-server ~]# sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config 
[root@nginx-server ~]# systemctl stop firewalld [root@nginx-server ~]# systemctl disable firewalld

启动并设置开机启动

[root@nginx-server ~]# systemctl start nginx [root@nginx-server ~]# systemctl enable nginx 

浏览器输入ip访问:
在这里插入图片描述

2、nginx 编译安装与配置使用

1、安装编译环境

yum -y install gcc gcc-c++

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

yum install -y pcre pcre-devel

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

yum install -y openssl openssl-devel

4、安装zlib

yum install -y zlib zlib-devel

5、创建用户nginx

useradd nginx
passwd nginx 

6、安装nginx

[root@localhost ~]# wget http://nginx.org/download/nginx-1.16.0.tar.gz 
[root@localhost ~]# tar xzf nginx-1.16.0.tar.gz -C /usr/local/
[root@localhost ~]# cd /usr/local/nginx-1.16.0/
[root@localhost nginx-1.16.0]# ./configure --prefix=/usr/local/nginx --group=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-
http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre --
with-http_realip_module --with-stream
[root@localhost nginx-1.16.0]# make && make install

7、Nginx 编译参数

# 查看 nginx 安装的模块 
[root@localhost ~]#/usr/local/nginx/sbin/nginx -V
# 模块参数具体功能 
--with-cc-opt='-g -O2 -fPIE -fstack-protector      //设置额外的参数将被添加到CFLAGS变量。(FreeBSD或者ubuntu使用)
--param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2' 
--with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now' 

--prefix=/usr/local/nginx                  //指向安装目录 
--conf-path=/etc/nginx/nginx.conf          //指定配置文件 
--http-log-path=/var/log/nginx/access.log  //指定访问日志 
--error-log-path=/var/log/nginx/error.log  //指定错误日志 
--lock-path=/var/lock/nginx.lock           //指定lock文件 
--pid-path=/run/nginx.pid                  //指定pid文件

--http-client-body-temp-path=/var/lib/nginx/body  //设定http客户端请求临时文件路径 
--http-fastcgi-temp-path=/var/lib/nginx/fastcgi   //设定http fastcgi临时文件路径
--http-proxy-temp-path=/var/lib/nginx/proxy       //设定http代理临时文件路径 
--http-scgi-temp-path=/var/lib/nginx/scgi         //设定http scgi临时文件路径
--http-uwsgi-temp-path=/var/lib/nginx/uwsgi       //设定http uwsgi临时文件路径

--with-debug                     //启用debug日志 
--with-pcre-jit                  //编译PCRE包含“just-in-time compilation” 
--with-ipv6                      //启用ipv6支持 
--with-http_ssl_module           //启用ssl支持 
--with-http_stub_status_module   //获取nginx自上次启动以来的状态 
--with-http_realip_module        //允许从请求标头更改客户端的IP地址值,默认为关
--with-http_auth_request_module  //实现基于一个子请求的结果的客户端授权。如果该子请求返回的2xx响应代码,所述接入是允许的。如果它返回401或403中,访问被拒绝与相应的错误代码。由子请求返回的任何其他响应代码被认为是一个错误。 
--with-http_addition_module      //作为一个输出过滤器,支持不完全缓冲,分部分响应请求 
--with-http_dav_module           //增加PUT,DELETE,MKCOL:创建集合,COPY和MOVE方法 默认关闭,需编译开启
--with-http_geoip_module         //使用预编译的MaxMind数据库解析客户端IP地址,得到变量值
--with-http_gunzip_module        //它为不支持“gzip”编码方法的客户端解压有“ContentEncoding: gzip”头的响应。
--with-http_gzip_static_module   //在线实时压缩输出数据流
--with-http_image_filter_module  //传输JPEG/GIF/PNG 图片的一个过滤器)(默认为不启用。gd库要用到)
--with-http_spdy_module          //SPDY可以缩短网页的加载时间 
--with-http_sub_module           //允许用一些其他文本替换nginx响应中的一些文本 
--with-http_xslt_module          //过滤转换XML请求
--with-mail                      //启用POP3/IMAP4/SMTP代理模块支持
--with-mail_ssl_module           //启用ngx_mail_ssl_module支持启用外部模块支持

8、修改配置文件/etc/nginx/nginx.conf

# 全局参数设置
worker_processes  4;              #设置nginx启动进程的数量,一般设置成与逻辑cpu数量相同 
error_log  logs/error.log;        #指定错误日志 
worker_rlimit_nofile 102400;      #设置一个nginx进程能打开的大文件数 
pid        /var/run/nginx.pid;
events {
	worker_connections  1024;     #设置一个进程的大并发连接数 
}
# http 服务相关设置 
http {
	include      mime.types;
	default_type  application/octet-stream;
	log_format  main  'remote_addr - remote_user [time_local] "request"'
	                  'status body_bytes_sent "$http_referer"'
	                  '"http_user_agent" "http_x_forwarded_for"';
	access_log  /var/log/nginx/access.log  main;    #设置访问日志的位置和格式
	sendfile          on;  #是否调用sendfile函数输出文件,一般设置为on,若nginx是用来进行磁盘IO负载应用时,可以设置为off,降低系统负载
	gzip              on;  #是否开启gzip压缩,将注释去掉开启
	keepalive_timeout  65; #设置长连接的超时时间 
# 虚拟服务器的相关设置
	server {
		listen		80;    #设置监听的端口
		server_name	 localhost;  #设置绑定的主机名、域名或ip地址 
		charset koi8-r;	   #设置编码字符 
		location / {
			root  /var/www/nginx;    #设置服务器默认网站的根目录位置,需要手动创建 
			index  index.html index.htm;   #设置默认打开的文档 
			}
		error_page  500 502 503 504  /50x.html;    #设置错误信息返回页面 
		location = /50x.html {
			root  html;     #这里的绝对位置是/usr/local/nginx/html
		}
	}
}

nginx.conf的组成:nginx.conf一共由三部分组成,分别为:全局块、events块、http块。在http块中又包含http全局块、多个server块。每个server块中又包含server全局块以及多个location块。在统一配置块中嵌套的配置快,各个之间不存在次序关系。

9、检测nginx配置文件是否正确

[root@localhost ~]# /usr/local/nginx/sbin/nginx -t 
[root@localhost ~]# mkdir -p /tmp/nginx

10、启动nginx服务

[root@localhost ~]# /usr/local/nginx/sbin/nginx

11、通过nging命令控制nginx服务

nginx -c /path/nginx.conf         # 以特定目录下的配置文件启动nginx:
nginx -s reload                   # 修改配置后重新加载生效
nginx -s reopen                   # 重新打开日志文件 
nginx -s stop                     # 快速停止nginx
nginx -s quit                     # 完整有序的停止nginx
nginx -t                          # 测试当前配置文件是否正确 
nginx -t -c /path/to/nginx.conf   # 测试特定的nginx配置文件是否正确

注意:
nginx -s reload 命令加载修改后的配置文件,命令下达后发生如下事件
1. Nginx的master进程检查配置文件的正确性,若是错误则返回错误信息,nginx继续采用原配置文件进行工作(因为worker未受到影响)
2. Nginx启动新的worker进程,采用新的配置文件
3. Nginx将新的请求分配新的worker进程
4. Nginx等待以前的worker进程的全部请求已经都返回后,关闭相关worker进程
5. 重复上面过程,知道全部旧的worker进程都被关闭掉

12、实现nginx开机自启

[root@localhost ~]# vim /etc/init.d/nginx 
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: -85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# 				proxy and IMAP/POP3 proxy server
# processname: nginx
# config:	   /etc/nginx/nginx.conf
# config:      /etc/sysconfig/nginx
# pidfile:     /var/run/nginx.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configguration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nging="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)

NGINX_CONF_FILE="/etc/nginx/nginx.conf"

[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx

lockfile=/var/lock/nginx

make_dirs() {
  # make required directories
  user=`nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
  options=`$nginx -V 2>&1 | grep 'configure arguments:'`
  for opt in $options; do
  	  if [ `echo $opt | grep '.*-temp-path'` ];then
  	  	  value=`echo $opt | cut -d "=" -f 2`
  	  	  if [ ! -d "$value" ];then
  	  	      # echo "creating" $value
  	  	      mkdir -p $value && chown -R $user $value
  	  	  fi
  	  fi
  done
}

start() {
	[ -x $nginx ] || exit 5
	[ -f $NGINX_CONF_FILE ] || exit 6
	make_dirs
	echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}

stop() {
	echo -n $"Stopping $prog: "
	killproc $prog -QUIT
	retval=$?
	echo
	[ $retval -eq 0 ] && rm -f $lockfile
	return $retval
}

restart() {
	configtest || return $?
	stop
	sleep 1
	start
}

reload() {
	configtest || return $?
	echo -n $"Reloading $prog: "
	killproc $nginx -HUP
	RETVAL=$?
	echo
}

force_reload() {
	restart
}

configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}

rh_status() {
	status $prog
}

rh_status_q() {
	rh_status >/dev/null 2>&1
}

case "$1" in
	start)
		rh_status_q && exit 0
		$1
		;;
	stop)
		rh_status_q || exit 0
		$1
		;;
	restart|configtest)
		$1
		;;
	reload)
		rh_status_q || exit 7
		$1
		;;
	force-reload)
		force_reload
		;;
	status)
		rh_status
		;;
	condrestart|try-restart)
		rh_status_q || exit 0
		;;
	*)
		echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
		exit 2
esac

添加权限

chmod +x /etc/init.d/nginx

重新加载系统启动文件

systemctl daemon-reload

启动并设置开机自启

systemctl start nginx
[root@localhost ~]# /sbin/chkconfig nginx on ---开机启动
10、nginx日志文件详解

nginx 日志文件分为log_formataccess_log两部分
log_format 定义记录的格式,其语法格式为
log_format 样式名称 样式详情

配置文件种默认有

log_format  main 'remote_addr - remote_user [time_local] "request" '
				 'status body_bytes_sent "$http_referer" '
				 '"http_user_agent" "http_x_forwarded_for"';

在这里插入图片描述在这里插入图片描述

nginx 高级应用

1.使用alias实现虚拟目录;

lcation /test {
		   alias   /var/www/hujinwen/;
		   index  index.html;  #访问http://ip/test时实际上访问是/var/www/hujinwen/index.html
       }

2、通过 stub_status 模块监控 nginx 的工作状态

  1. 通过 nginx -V 命令查看是否已安装 stub_status 模块

  2. 编辑 /etc/nginx/nginx.conf 配置文件

# 添加以下内容~~
location /nginx-status {
		syub_status on;
		access_log    /var/log/nginx/nginxstatus.log;  #设置日志文件的位置 
		auth_basic    "nginx-status";  #指定认证机制(与location后面的内容相同即可)
		auth_basic_user_file    /etc/nginx/htpasswd;  #指定认证的密码文件
        }
  1. 创建认证口令文件并添加用户qianfeng和zdgg,密码用md5加密
[root@localhost ~]# yum install -y httpd-tools  #htpasswd 是开源 http 服务器 apache httpd 的一个命令工具,用于生成 http 基本认证的密码文件
htpasswd -c -m /etc/nginx/htpasswd hujinwen  # -c 创建解密文件,-m MD5加密
htpasswd -m /etc/nginx/htpasswd zsgg
  1. 重启服务
  2. 客户端访问http://ip/nginx-status即可

3、使用 limit_rate 限制客户端传输数据的速度

编辑/etc/nginx/nginx.conf

location / {
			root   /var/www/nginx/;
			index  index.html index.htm;
			limit_rate  2k;  #对每个连接的限速为2k/s
        }

重启服务

注意要点

  • 配置文件中的每个语句要以 ; 结尾
  • 使用 htpasswd 命令需要先安装 httpd
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值