设为首页 收藏本站
查看: 922|回复: 0

[经验分享] nginx网站服务(下)

[复制链接]

尚未签到

发表于 2018-11-9 07:54:07 | 显示全部楼层 |阅读模式
第1章 回顾
1.1 nginx软件服务
1.1.1 软件概念以及特性介绍
  1. 可以实现高并发访问处理,消耗资源小
  2. 软件知识功能很多(web服务功能  反向代理功能  缓存功能)
  3. 利用异步网络IO模型,实现快速处理用户请求(epoll)
1.1.2 软件部署过程
  1)下载解压软件(nginx.org)
  2)安装依赖软件
  openssl-devel  pcre-devel
  3)创建出一个worker进程管理用户
  4)进行nginx软件编译安装
  a 进行软件配置     ./configure
  b 进行软件编译     make
  c 进行软件编译安装 make install
  5)创建程序目录软链接
  6)启动nginx服务,利用curl命令或浏览器进行访问测试
1.1.3 介绍软件目录结构信息
  conf   --- 软件配置文件保存目录
  html   --- 软件服务站点目录
  logs   --- 软件服务日志默认保存目录

  sbin   --- 软件服务管理命令服务(nginx -t -s>1.1.4 介绍服务配置文件参数信息(默认)
  规范一:大括号要成对出现
  规范二:每行信息结尾要注意有分号 ;
  规范三:相应参数指令只能放置在指定区块
1.1.5 搭建简单的web网站  
第2章 虚拟主机的概念和类型介绍
  所谓虚拟主机,在Web服务里就是一个独立的网站站点,这个站点对应独立的域名(也可能是IP或端口), 虚拟主机配置上有三种类型
2.1 基于域名的虚拟主机配置
2.1.1 修改配置文件
  [root@web01 conf]# vim nginx.conf
  worker_processes  1;
  events {
  worker_connections  1024;
  }
  http {
  include       mime.types;
  default_type  application/octet-stream;
  sendfile        on;
  keepalive_timeout  65;
  server {
  listen       80;
  server_name  www.wuhuang.com;
  root   html/www;
  index  index.html index.htm;
  }
  server {
  listen       80;
  server_name  bbs.wuhuang.com;
  root   html/bbs;
  index  index.html index.htm;
  }
  server {
  listen       80;
  server_name  blog.wuhuang.com;
  root   html/blog;
  index  index.html index.htm;
  }
  }
2.1.2 网站目录和文件环境准备
  mkdir /application/nginx/html/{www,bbs,blog} -p
  for name in www bbs blog;do echo "10.0.0.7 web01 $name" >/application/nginx/html/$name/index.html;done
  [root@web01 conf]# mkdir /application/nginx/html/{www,bbs,blog} -p
  [root@web01 conf]# for name in www bbs blog;do echo "10.0.0.7 web01 $name" >/application/nginx/html/$name/index.html;done
  [root@web01 conf]# ll ../html/
  total 20
  -rw-r--r-- 1 root root  537 Feb  5 19:53 50x.html
  drwxr-xr-x 2 root root 4096 Feb  5 20:03 bbs
  drwxr-xr-x 2 root root 4096 Feb  5 20:03 blog
  -rw-r--r-- 1 root root  612 Feb  5 19:53 index.html
  drwxr-xr-x 2 root root 4096 Feb  5 20:03 www
  [root@web01 conf]# for name in www bbs blog;do cat /application/nginx/html/$name/index.html;done
  10.0.0.7 web01 www
  10.0.0.7 web01 bbs
  10.0.0.7 web01 blog
2.1.3 检查配置文件语法,进行服务重启或者启动
  [root@web01 conf]# /application/nginx/sbin/nginx -t
  nginx: the configuration file /application/nginx-1.12.2/conf/nginx.conf syntax is ok
  nginx: configuration file /application/nginx-1.12.2/conf/nginx.conf test is successful

  [root@web01 conf]# /application/nginx/sbin/nginx -s>  [root@web01 conf]# netstat -lntup |grep nginx
  tcp        0      0 0.0.0.0:80                  0.0.0.0:*                 LISTEN      8337/nginx
2.1.4 利用curl或者浏览器进行访问测试
  需要对虚拟主机域名进行解析(编写hosts文件-linux里面hosts文件 windows里面hosts)
  [root@web01 conf]# vim /etc/hosts
  127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
  ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
  172.16.1.5      lb01
  172.16.1.6      lb02
  172.16.1.7      web01 www.wuhuang.com bbs.wuhuang.com blog.wuhuang.com
  [root@web01 conf]# for name in www bbs blog;do curl $name.wuhuang.com;sleep 1;done
  10.0.0.7 web01 www
  10.0.0.7 web01 bbs
  10.0.0.7 web01 blog
  当客户端访问nginx服务端,返回的状态码信息为304时,表示进行读取缓存处理
2.2 基于端口的虚拟主机配置
2.2.1 修改配置文件
  [root@web01 conf]# vim nginx.conf
  worker_processes  1;
  events {
  worker_connections  1024;
  }
  http {
  include       mime.types;
  default_type  application/octet-stream;
  sendfile        on;
  keepalive_timeout  65;
  server {
  listen       80;
  server_name  www.wuhuang.com;
  root   html/www;
  index  index.html index.htm;
  }
  server {
  listen       81;                                    --- 将默认80端口号改为81
  server_name  bbs.wuhuang.com;
  root   html/bbs;
  index  index.html index.htm;
  }
  server {
  listen       80;
  server_name  blog.wuhuang.com;
  root   html/blog;
  index  index.html index.htm;
  }
  }
2.2.2 优化nginx操作
  [root@web01 conf]# vim /etc/profile
  [root@web01 conf]# tail -1 /etc/profile
  export PATH=$PATH:/application/nginx/sbin/
2.2.3 重启nginx服务
  [root@web01 conf]# nginx -t
  nginx: the configuration file /application/nginx-1.12.2/conf/nginx.conf syntax is ok
  nginx: configuration file /application/nginx-1.12.2/conf/nginx.conf test is successful

  [root@web01 conf]# nginx -s>2.2.4 验证
DSC0000.jpg

DSC0001.jpg

DSC0002.jpg

2.2.5 网站访问过程原理图
DSC0003.jpg

2.3 基于IP的虚拟主机配置
2.3.1 修改配置文件
  [root@web01 conf]# vim nginx.conf
  worker_processes  1;
  events {
  worker_connections  1024;
  }
  http {
  include       mime.types;
  default_type  application/octet-stream;
  sendfile        on;
  keepalive_timeout  65;
  server {
  listen       10.0.0.7:80;
  server_name  www.wuhuang.comg;
  root   html/www;
  index  index.html index.htm;
  }
  #  server {
  #      listen       81;
  #      server_name  bbs.wuhuang.com;
  #      root   html/bbs;
  #      index  index.html index.htm;
  #  }
  #  server {
  #      listen       80;
  #      server_name  blog.wuhuang.com;
  #      root   html/blog;
  #      index  index.html index.htm;
  #  }
  }
  强调说明(*****):当nginx配置文件中,涉及到IP地址信息改动,都需要重启nginx服务,
  不能采用平滑重启,否则配置不生效
2.3.2 重启服务
  [root@web01 conf]# nginx -s stop
  [root@web01 conf]# nginx
  [root@web01 conf]#  netstat -lntup|grep nginx
  tcp        0      0 10.0.0.7:80                 0.0.0.0:*                 LISTEN      8440/nginx
2.3.3 验证
  [root@web01 conf]# curl 10.0.0.7
  10.0.0.7 web01 www
  [root@web01 conf]# curl 172.16.1.7
  curl: (7) couldn't connect to host
  [root@web01 conf]# vim /etc/hosts
  127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
  ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
  172.16.1.7      web01 bbs.wuhuang.com blog.wuhuang.com
  10.0.0.7        www.wuhuang.com
  注意:同一个IP地址可以对应多个域名,但一个域名只能对应一个IP地址
  [root@web01 conf]# curl www.wuhuang.com
  10.0.0.7 web01 www
2.4 企业规范优化Nginx配置文件
2.4.1 第一个里程碑:创建扩展目录,生成虚拟主机配置文件
  [root@web01 conf]# vim nginx.conf
  13         root   html/www;
  14         index  index.html index.htm;
  15     }
  16     server {
  17         listen       80;
  18         server_name  bbs.wuhuang.com;
  19         root   html/bbs;
  20         index  index.html index.htm;
  21     }
  22     server {
  23         listen       80;
  24         server_name  blog.wuhuang.com;
  25         root   html/blog;
  26         index  index.html index.htm;
  27     }
  28 }
  [root@web01 conf]# mkdir extra
  [root@web01 conf]# sed -n '10,15p' nginx.conf >extra/www.conf
  [root@web01 conf]# sed -n '16,21p' nginx.conf >extra/bbs.conf
  [root@web01 conf]# sed -n '22,27p' nginx.conf >extra/blog.conf
  [root@web01 conf]# cat extra/blog.conf
  server {
  listen       80;
  server_name  blog.wuhuang.com;
  root   html/blog;
  index  index.html index.htm;
  }
2.4.2 第二个里程碑:修改nginx主配置文件,加载相应虚拟主机配置文件
  [root@web01 conf]# cat nginx.conf
  worker_processes  1;
  events {
  worker_connections  1024;
  }
  http {
  include       mime.types;
  default_type  application/octet-stream;
  sendfile        on;
  keepalive_timeout  65;
  include       extra/www.conf;
  include       extra/bbs.conf;
  include       extra/blog.conf;
  }
2.4.3 第三里程碑:重启服务,进行检验测试
  [root@web01 html]# nginx -t
  nginx: the configuration file /application/nginx-1.12.2/conf/nginx.conf syntax is ok
  nginx: configuration file /application/nginx-1.12.2/conf/nginx.conf test is successful

  [root@web01 html]# nginx -s>  [root@web01 html]# for name in www bbs blog;do curl $name.wuhuang.com;sleep 1;done
  10.0.0.7 web01 www
  10.0.0.7 web01 bbs
  10.0.0.7 web01 blog
2.5 Nginx虚拟主机的别名配置
  [root@web01 extra]# cat bbs.conf
  server {
  listen       80;
  server_name  bbs.wuhuang.com bbs.com;
  root   html/bbs;
  index  index.html index.htm;
  }
  说明:添加别名信息需要设置到hosts解析文件中
  [root@web01 extra]# cat /etc/hosts
  127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
  ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
  172.16.1.5      lb01
  172.16.1.6      lb02
  172.16.1.7      web01  www.wuhuang.com  bbs.wuhuang.com  blog.wuhuang.com bbs.com
  验证
  [root@web01 extra]# nginx -t
  nginx: the configuration file /application/nginx-1.12.2/conf/nginx.conf syntax is ok
  nginx: configuration file /application/nginx-1.12.2/conf/nginx.conf test is successful

  [root@web01 extra]# nginx -s>  [root@web01 extra]# curl bbs.com
  10.0.0.7 web01 bbs
2.6 Nginx状态信息功能实战
  为什么在编译安装时,需要配置状态模块?
  可以查看nginx运行状态信息。
  官方参考链接:http://nginx.org/en/docs/http/ngx_http_stub_status_module.html#stub_status
  [root@web01 conf]# cat extra/state.conf
  server{
  listen  80;
  server_name  state.wuhuang.com;
  location / {
  stub_status on;
  access_log   off;
  }
  }
  [root@web01 conf]# cat nginx.conf
  worker_processes  1;
  events {
  worker_connections  1024;
  }
  http {
  include       mime.types;
  default_type  application/octet-stream;
  sendfile        on;
  keepalive_timeout  65;
  include       extra/www.conf;
  include       extra/bbs.conf;
  include       extra/blog.conf;
  include       extra/state.conf;
  }
  说明:以上信息配置,将状态模块域名配置到windows系统的hosts文件中和/etc/hosts中。
  [root@web01 conf]# nginx -t
  nginx: the configuration file /application/nginx-1.12.2/conf/nginx.conf syntax is ok
  nginx: configuration file /application/nginx-1.12.2/conf/nginx.conf test is successful

  [root@web01 conf]# nginx -s>  [root@web01 conf]# curl state.wuhuang.com
  Active connections: 1
  server accepts handled requests
  9 9 9
  Reading: 0 Writing: 1 Waiting: 0
  状态模块说明:
  Active connections: 1                           ——当前客户端的连接数量(包含waiting连接数)
  server accepts handled requests         ——accepts:接收客户端连接的总数(只接受http协议信息)
  9 9 9                                                    —— handled:处理连接的总数(处理的是accepts接收的数据)
  —— requests:客户端请求的总数(包括TCP建立接连)
  Reading: 0 Writing: 1 Waiting: 0          —— Reading:监控请求头的连接数
  —— writing:监控回应客户端的连接数
  ——waiting:监控空闲客户端的连接请求等待数
DSC0004.jpg

第3章 Nginx服务日志信息
3.1 错误日志
3.1.1 error_log的语法格式及参数语法说明:
  error_log     file        level
  关键字     日志文件   错误日志级别
  日志信息错误级别分为8种:
  0  EMERG(紧急):会导致主机系统不可用的情况
  1  ALERT(警告):必须马上采取措施解决的问题
  2  CRIT(严重):比较严重的情况
  3  ERR(错误):运行出现错误
  4  WARNING(提醒):可能会影响系统功能的事件
  5  NOTICE(注意):不会影响系统但值得注意
  6  INFO(信息):一般信息
  7  DEBUG(调试):程序或系统调试信息等
  error_log的默认值为:
  Default:  error_log logs/error.log error;
  可以放置的标签段为:
  Context:main, http, mail, stream, server, location
3.1.2 Nginx错误日志配置
  [root@web01 data]# cat /application/nginx/conf/nginx.conf
  worker_processes  1;
  error_log  logs/error.log;
  events {
  worker_connections  1024;
  }
  http {
  include       mime.types;
  default_type  application/octet-stream;
  sendfile        on;
  keepalive_timeout  65;
  include       extra/www.conf;
  include       extra/bbs.conf;
  include       extra/blog.conf;
  include       extra/state.conf;
  }
  
3.2 访问日志(重点关注)
  [root@web01 data]# cat /application/nginx/conf/nginx.conf
  worker_processes  1;
  error_log  logs/error.log;
  events {
  worker_connections  1024;
  }
  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  logs/access.log  main;
  sendfile        on;
  keepalive_timeout  65;
  include       extra/www.conf;
  include       extra/bbs.conf;
  include       extra/blog.conf;
  include       extra/state.conf;
  }
  [root@web01 extra]# cat bbs.conf
  server {
  listen       80;
  server_name  bbs.wuhuang.com;
  location / {
  access_log on;
  }
  root   html/bbs;
  index  index.html index.htm;
  }
  Nginx记录日志的默认参数配置:
  access_log  logs/access.log  main;                    --- 调用定义格式信息,生成访问日志
  $remote_addr       10.0.0.1           --- 访问客户端的源地址信息
  $remote_user          -               --- 访问客户端认证用户信息
  [$time_local]                         --- 显示访问时间
  $request        GET / HTTP/1.1        --- 请求行信息
  $status              304              --- 状态码信息(304状态码利用缓存显示页面信息)
  $body_bytes_sent                      --- 服务端响应客户端的数据大小信息
  $http_referer                         --- 记录链接到网站的域名信息
  $http_user_agent                   --- 用户访问网站客户端软件标识信息(例:浏览器、手机客户端)
  用户利用客户端浏览器测试访问时,win10默认浏览器会有异常问
  $http_x_forwarded_for                 --- 反向代理
  官方链接:http://nginx.org/en/docs/http/ngx_http_log_module.html#access_log
3.3 日志要进行切割
3.3.1 利用shell脚本实现日志切割
  [root@web01 scripts]# cat cut_log.sh
  #!/bin/bash
  data_info=$(date +%F-%H:%M)
  mv /application/nginx/logs/access.log /application/nginx/logs/access.log.$data_info

  /application/nginx/sbin/nginx -s>  # cut nginx log cron
  * */6 * * * /bin/sh /server/scripts/cut_log.sh &>/dev/null
  写入定时任务
  # cut nginx log cron
  * */6 * * * /bin/sh /server/scripts/cut_log.sh &>/dev/null
3.3.2 利用logrotate服务程序进行日志切割
  作用:logrotate的配置文件是/etc/logrotate.conf,通常不需要对它进行修改。日志文件的轮循设置在独立的     配置文件中,它们放在/etc/logrotate.d/目录下。
  logrotate全局配置参数说明:
  
  vim /etc/logrotate.conf
  
  weekly ###日志文件将按月轮循
  
  rotate 4 ###一次将最多存储4个归档日志
  
  create ###在生成轮询日志后,会自动创建一个新的文件
  
  dateext ###生成的轮询日志后面加上时间格式
  
  compress ###生成的轮询日志是否压缩,默认被注释
  
  include /etc/logrotate.d ###存放日志文件的轮询配置
  vim /etc/logrotate.d/log-file
  /var/log/log-file {
  monthly
  -rotate 5
  compress
  delaycompress
  missingok
  create 644 root root
  postrotate
  /usr/bin/killall -HUP rsyslogd
  endscript
  }
第4章 location区块作用
4.1 企业需求解决:
  搭建好一台nginx的web服务器。配置好内网卡地址与外网卡地址
  web服务的网站域名为www.etiantian.org,站点目录为html/www
  要求内网用户可以访问网站http://www.etiantian.org/AV资源信息
  要求外网用户禁止访问网站http://www.etiantian.org/AV资源信息
4.2 部署过程
4.2.1 精确控制允许和拒绝
  location / {
  allow 172.16.1.0/24;              ——允许172.16.1.0网段访问
  deny  all;                      ——拒绝所有访问
  }
4.2.2 访问/AV 资源有访问控制
  定位/AV资源不能随意访问
  location 进行资源定位  ——相当于if 判断,满足什么做什么
  格式:
  location /AV {
  }
4.2.3 创建测试访问资源信息
  创建测试站点目录
  mkdir /application/nginx/html/www/AV
  curl  -H host:www.wuhuang.com 10.0.0.7/lalala.html        --- 表示指定访问nginx服务端哪一个虚拟主机
4.2.4 测试
  [root@nfs01 ~]# curl -H host:www..wuhuang.com 172.16.1.7/AV/lalala.html
  wuhuang01                                                                ——内网可以访问
  [root@nfs01 ~]# curl -H host:www.etiantian.org 10.0.0.7/AV//lalala.html
  
  403 Forbidden                                       ——403拒绝访问
  
  403 Forbidden
  nginx/1.12.2
  
  
4.3 location语法格式
  Syntax: location [ = | ~ | ~*|^~ ] uri {  ... }             ——uri就是域名后面的信息
4.3.1 比较
  -eq    等于
  -ne    不等于
  -le    小于等于
  -lt    小于
  -ge    大于等于
  -gt    大于
4.3.2 优先顺序
  = ——精确匹配(不要多余的)     1
  ~ ——区分大小写匹配           3
  ~* ——不区分大小写匹配(grep -i)     3
  ^~ ——优先匹配(优先级)        2
  /AV ——指定要匹配的目录资源        3
  / ——指定匹配站点目录             默认匹配
  ! ——表示取反匹配
4.3.3 测试匹配优先级方法
  第一步:编写测试配置文件
  [root@web01 extra]# cat www.conf
  server {
  listen       80;
  server_name  www.wuhuang.com;
  root   html/www;
  location / {
  return 401;
  }
  location = / {
  return 402;
  }
  location /documents/ {
  return 403;
  }
  location ^~ /images/ {
  return 404;
  }
  location ~* \.(gif|jpg|jpeg)$ {
  return 500;
  }
  access_log logs/access_www.log main;
  }
  第二步:根据返回状态码,确认优先级
  总结取状态码方法:
  1)curl -I www.wuhuang.com/wu1/ 2>/dev/null|awk 'NR==1{print $2}'
  2)curl -I www.wuhuang.com/wu1/ -s|awk 'NR==1{print $2}'
  3)curl -s -I www.wuhuang.com/wu1/ -w "%{http_code}\n" -o /dev/null
  作用:编译以后进行网站运行状态监控
  总结curl命令参数:
  -v         --- 显示用户访问网站详细报文信息(请求报文 响应报文)
  -I         --- 显示响应报文起始行和响应头部信息
  -H host:   --- 修改请求报文host字段信息
  -L         --- 进行访问跳转追踪
  -u user:password   --- 指定认证用户信息
  -o         --- 将输出内容可以指定到空
  -w         --- 指定需要输出显示的信息
  -s         --- 不显示错误输出,将错误信息追加到空
4.4 rewrite模块的使用——地址重写
4.4.1 作用功能
  1. 将地址信息进行重写,实现域名地址信息跳转
  2. 用于做伪静态
  rewrite应用标签:serverlocationif
  如何实现类似百度重写域名的功能?
  baidu.com  ===>  www.baidu.com
  etiantian.org  ===> bbs.etiantian.org
4.4.2 rewrite指令实践操作一:(错误)
  [root@web01 extra]# cat bbs.conf
  server {
  listen       80;
  server_name  bbs.wuhuang.com bbs.com;
  rewrite ^/(.*) http://bbs.wuhaung.com/$1 permanent;
  root   html/bbs;
  index  index.html index.htm;
  }
  [root@web01 extra]# curl -L etiantian.org     --- 进行访问跳转追踪
  curl: (47) Maximum (50) redirects followed
  [root@web01 extra]# curl -Lv etiantian.org   --- 显示无限循环过程
  说明:以上配置进入了无限循环状态
4.4.3 rewrite指令实践操作二:(正确)
  [root@web01 extra]# cat bbs.conf
  server {
  listen 80;
  server_name etiantian.org;
  rewrite ^/(.*) http://bbs.wuhuang.com/$1 permanent;
  }
  server {
  listen       80;
  server_name  bbs.wuhuang.com bbs.com;
  root   html/bbs;
  index  index.html index.htm;
  }
  说明:以上状态不会循环,跳转成bbs,后再次重新匹配时,是以bbs的域名查找,这时候就不匹配第一个server_name了,直接进入下一个server区块
4.4.4 rewrite指令实践操作三:(正确)
  [root@web01 extra]# cat bbs.conf
  server {
  listen       80;
  server_name  bbs.wuhuang.com bbs.com;
  if ($host ~* "^wuhuang.com$") {                      ——if这里相当于location
  rewrite ^/(.*) http://bbs.wuhuang.com/$1 permanent;
  }
  root   html/bbs;
  index  index.html index.htm;
  }
  说明:$host就是主机头信息,~*:不区分大小写,后面的是以wuhuang开头,com结尾。经过rewite就跳转为bbs, 然后在重新访问,这个时候就不满足if语句的条件了,那么就继续读取下一个location
4.4.5 Nginx的rewrite功能在企业里应用场景
  Ø 可以调整用户浏览的URL,使其看起来更规范,合乎开发及产品人员的需求。
  Ø 为了让搜索引擎收录网站内容,并让用户体验更好,企业会将动态URL地址伪装成静态地址提供服务。
  Ø 网站换新域名后,让旧域名的访问跳转到新的域名上,例如:让京东的360buy换成了jd.com。
  Ø 根据特殊变量、目录、客户端的信息进行URL跳转等。
第5章 Nginx访问认证
5.1 部署过程
5.1.1 第一个里程碑:编写配置文件,加入认证信息
  auth_basic           "wuhuang training";
  auth_basic_user_file /application/nginx/conf/htpasswd;
  [root@web01 extra]# cat bbs.conf
  server {
  listen       80;
  server_name  bbs.wuhuang.com bbs.com;
  auth_basic           "wuhuang training";
  auth_basic_user_file /application/nginx/conf/htpasswd;
  if ($host ~* "^wuhuang.com$") {
  rewrite ^/(.*) http://bbs.wuhuang.com/$1 permanent;
  }
  root   html/bbs;
  index  index.html index.htm;
  }
5.1.2 第二个里程碑:编写认证文件
  利用htpasswd命令生成密文密码信息
  rpm -qf `which htpasswd`
  httpd-tools-2.2.15-59.el6.centos.x86_64          ——安装apache(需要用其中的htpasswd命令)
  htpasswd -bc /application/nginx/conf/htpasswd wuhuang 123456    ---生成认证文件
  chmod 400 /application/nginx/conf/htpasswd
  chown www.www /application/nginx/conf/htpasswd
  说明:   -c     #创建一个新的密码文件
  -b    #采用免交互的方式输入用户的密码信
5.1.3 第三个里程碑:重启服务进行测试
  1. 401 Authorization Required       --- 要求用户进行认证
  2. 500                            --- worker进程无法读取用户请求的问题,权限问题
  [root@web01 extra]# curl bbs.wuhuang.com -u wuhuang
  Enter host password for user 'wuhuang':
  10.0.0.7 web01 bbs
  [root@web01 extra]# curl bbs.etiantian.org -u wuhuang:123456
  10.0.0.7 web01 bbs
5.2 总结curl命令参数
  -v         --- 显示用户访问网站详细报文信息(请求报文 响应报文)
  -I         --- 显示响应报文起始行和响应头部信息
  -H host:   --- 修改请求报文host字段信息
  -L         --- 进行访问跳转追踪
  -u user:password   --- 指定认证用户信息
  -o         --- 将输出内容可以指定到空
  -w         --- 指定需要输出显示的信息
  -s         --- 不显示错误输出,将错误信息追加到空


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-632578-1-1.html 上篇帖子: Nginx Location配置总结及rewrite-linux开源 下篇帖子: Nginx的alias的用法及与root的区别
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表