nginx網站服務(下)

第1章 回顧

1.1 nginx軟件服務

1.1.1 軟件概念以及特性介紹

1. 能夠實現高併發訪問處理,消耗資源小html

2. 軟件知識功能不少(web服務功能  反向代理功能  緩存功能)linux

3. 利用異步網絡IO模型,實現快速處理用戶請求(epollnginx

1.1.2 軟件部署過程

  1)下載解壓軟件(nginx.orgweb

2)安裝依賴軟件shell

      openssl-devel  pcre-develapache

3)建立出一個worker進程管理用戶vim

4)進行nginx軟件編譯安裝windows

       a 進行軟件配置     ./configurecentos

       b 進行軟件編譯     make瀏覽器

       c 進行軟件編譯安裝 make install

5)建立程序目錄軟連接

6)啓動nginx服務,利用curl命令或瀏覽器進行訪問測試

1.1.3 介紹軟件目錄結構信息

  conf   --- 軟件配置文件保存目錄

  html   --- 軟件服務站點目錄

  logs   --- 軟件服務日誌默認保存目錄

  sbin   --- 軟件服務管理命令服務(nginx -t -s reload stop

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 reload

[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 reload

2.2.4 驗證

image.png 

 

image.png 

image.png 

2.2.5 網站訪問過程原理圖

image.png 

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 reload

[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 reload

[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 reload

[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:監控空閒客戶端的鏈接請求等待數

image.png 

第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 reload

 

# 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 企業需求解決:

     搭建好一臺nginxweb服務器。配置好內網卡地址與外網卡地址

     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

<html>

<head><title>403 Forbidden</title></head>                                       ——403拒絕訪問

<body bgcolor="white">

<center><h1>403 Forbidden</h1></center>

<hr><center>nginx/1.12.2</center>

</body>

</html>

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;

       }

 第二步:根據返回狀態碼,確認優先級

 

總結取狀態碼方法:

1curl -I www.wuhuang.com/wu1/ 2>/dev/null|awk 'NR==1{print $2}'

   2curl -I www.wuhuang.com/wu1/ -s|awk 'NR==1{print $2}'

3curl -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 Nginxrewrite功能在企業裏應用場景

Ø 能夠調整用戶瀏覽的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         --- 不顯示錯誤輸出,將錯誤信息追加到空

相關文章
相關標籤/搜索