1.使用alias实现虚拟目录;
location /test {
            alias   /var/www/qianfeng/;
            index  index.html; #访问http://ip/test时实际上访问是/var/www/qianfeng/index.html
        }
? 1、通过 nginx -V 命令查看是否已安装 stub_status 模块
? 2、编辑 /etc/nginx/nginx.conf 配置文件
#添加以下内容~~ 
location /nginx-status { 
      stub_status on; 
      access_log    /var/log/nginx/nginxstatus.log;    #设置日志文件的位置 
      auth_basic    "nginx-status";    #指定认证机制(与location后面的内容相同即可) 
      auth_basic_user_file    /etc/nginx/htpasswd;     #指定认证的密码文件 
      }
3.创建认证口令文件并添加用户qianfeng和zdgg,密码用md5加密
[root@localhost ~]# yum install -y httpd-tools  #htpasswd 是开源 http 服务器 apache httpd 的一个命令工具,用于生成 http 基本认证的密码文件
htpasswd -c -m /etc/nginx/htpasswd qianfeng             # -c 创建解密文件,-m MD5加密
htpasswd -m /etc/nginx/htpasswd zsgg
4、重启服务
5、客户端访问 http://ip/nginx-status 即可
1、编辑/etc/nginx/nginx.conf
location / {
            root   /var/www/nginx/;
            index  index.html index.htm;
            limit_rate  2k;  #对每个连接的限速为2k/s
        }
重启服务
注意要点:
? 配置文件中的每个语句要以 ; 结尾
? 使用 htpasswd 命令需要先安装 httpd-tools
原文:https://www.cnblogs.com/pengpengboshi/p/13167854.html