1. 程式人生 > >第二十一課 LNMP(中)

第二十一課 LNMP(中)

目錄

1. 預設虛擬主機
2. Nginx 使用者認證
3. Nginx 域名重定向
4. Nginx 訪問日誌
5. Nginx 日誌切割
6. 靜態檔案不記錄日誌和過期時間
7. Nginx 防盜鏈
8. Nginx 訪問控制
9. Nginx 解析 php 相關配置
10. Nginx 代理

1. 預設虛擬主機

1.1 配置

1.1.1 修改 nginx.conf,去掉 server 塊,增加 include 語句
[[email protected]
~]# vim /usr/local/nginx/conf/nginx.conf user nobody nobody; worker_processes 2; error_log /usr/local/nginx/logs/nginx_error.log crit; pid /usr/local/nginx/logs/nginx.pid; worker_rlimit_nofile 51200; events { use epoll; worker_connections 6000; } http { include mime.types; default_type application/octet-stream; server_names_hash_bucket_size 3526
; server_names_hash_max_size 4096; log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]' ' $host "$request_uri" $status' ' "$http_referer" "$http_user_agent"'; sendfile on; tcp_nopush on; keepalive_timeout 30; client_header_timeout 3m; client_body_timeout 3
m; send_timeout 3m; connection_pool_size 256; client_header_buffer_size 1k; large_client_header_buffers 8 4k; request_pool_size 4k; output_buffers 4 32k; postpone_output 1460; client_max_body_size 10m; client_body_buffer_size 256k; client_body_temp_path /usr/local/nginx/client_body_temp; proxy_temp_path /usr/local/nginx/proxy_temp; fastcgi_temp_path /usr/local/nginx/fastcgi_temp; fastcgi_intercept_errors on; tcp_nodelay on; gzip on; gzip_min_length 1k; gzip_buffers 4 8k; gzip_comp_level 5; gzip_http_version 1.1; gzip_types text/plain application/x-javascript text/css text/htm application/xml; include vhost/*.conf; # 刪掉 server 塊後,增加這一句 }
1.1.2 在 conf 目錄下生成 vhost 目錄,並新建虛擬主機的配置檔案
[root@LNMP ~]# mkdir /usr/local/nginx/conf/vhost

[root@LNMP ~]# vim /usr/local/nginx/conf/vhost/default.conf
server
{
    listen 80 default_server;  # 指定監聽埠,且指定該虛擬主機為這個監聽埠上的預設虛擬主機
    server_name aaa.com;   # 設定主機名
    index index.html index.htm index.php;   # 指定索引頁
    root /data/wwwroot/default;    # 指定站點根目錄
}
1.1.3 建立對應的目錄及索引頁
[root@LNMP ~]# mkdir -p /data/wwwroot/default/

[root@LNMP ~]# echo "This is the default virtual site" > /data/wwwroot/default/index.html
1.1.4 語法檢查、重新整理配置

我已提前將 /usr/local/nginx/sbin 加入到 PATH 變數中,所以可以直接使用 nginx 命令

[[email protected] ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful


[[email protected] ~]# nginx -s reload

1.2 驗證

1.2.1 curl 驗證
[[email protected] ~]# curl localhost
This is the default virtual site

[[email protected] ~]# curl -x 192.168.1.100:80 asdfgahalsdfj.com
This is the default virtual site
1.2.2 瀏覽器驗證

提前修改 hosts 檔案,將測試伺服器的IP 與 你希望輸入的域名對應上

2. Nginx 使用者認證

2.1 配置

2.1.1 修改預設虛擬主機的配置檔案 default.conf,在 server 塊中增加 location 塊
[[email protected] vhost]# vim default.conf 

server
{
        listen 80 default_server;
        server_name aaa.com;
        index index.html index.htm index.php;
        root /data/wwwroot/default;


        location /         # 指定配置應用的目錄(相對於站點根目錄而言)
        {   
                auth_basic "The Auth of Choco's default site"; # 認證的提示資訊
                auth_basic_user_file /data/.htpasswd;  # 認證用的賬號/密碼檔案
        }   
}
2.1.2 在 default.conf 中指定的位置,生成賬號/密碼檔案

可通過使用 htpasswd 命令生成,但需提前安裝 httpd-tools

[root@LNMP ~]# yum -y install httpd-tools

[root@LNMP ~]# !htpasswd -c -m /data/.htpasswd chocolee911
New password: 
Re-type new password: 
2.1.3 語法檢查、重新整理配置
[[email protected] ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful


[[email protected] ~]# nginx -s reload

2.2 驗證

2.2.1 curl 驗證
## 不指定賬戶,HTTP 報 401
[[email protected] ~]# curl -x 192.168.1.100:80 www.abc.com -I
HTTP/1.1 401 Unauthorized
Server: nginx/1.12.2
Date: Thu, 05 Jul 2018 04:06:09 GMT
Content-Type: text/html
Content-Length: 195
Connection: keep-alive
WWW-Authenticate: Basic realm="The Auth of Choco's default site"

## 指定賬戶,並輸入密碼後,HTTP 報 200
[[email protected] ~]# curl -x 192.168.1.100:80 www.abc.com -u chocolee911 -I
Enter host password for user 'chocolee911':
HTTP/1.1 200 OK
Server: nginx/1.12.2
Date: Thu, 05 Jul 2018 04:06:33 GMT
Content-Type: text/html
Content-Length: 33
Last-Modified: Thu, 05 Jul 2018 03:45:26 GMT
Connection: keep-alive
ETag: "5b3d9456-21"
Accept-Ranges: bytes

## 你也可以顯式地在命令中直接輸入密碼,也能正常訪問
[[email protected] ~]# curl -x 192.168.1.100:80 www.abc.com -u chocolee911:123123 -I
HTTP/1.1 200 OK
Server: nginx/1.12.2
Date: Thu, 05 Jul 2018 04:07:56 GMT
Content-Type: text/html
Content-Length: 33
Last-Modified: Thu, 05 Jul 2018 03:45:26 GMT
Connection: keep-alive
ETag: "5b3d9456-21"
Accept-Ranges: bytes
2.2.2 瀏覽器驗證
  • 訪問站點時會提示輸入密碼

  • 如果不輸入或輸錯,會報401

  • 如果伺服器端的賬戶/密碼檔案未正確建立,不論輸入密碼正確與否,都會報403

  • 正確輸入後可正常訪問

3. Nginx 域名重定向

3.1 配置

3.1.1 在 vhost 目錄中新建配置檔案 test.com.conf
[root@LNMP ~]# vim /usr/local/nginx/conf/vhost/test.com.conf 

server
{
        listen 80; 
        server_name test.com test1.com test2.com; 
        index index.html;
        root /data/wwwroot/test.com;

        if ($host != 'test.com')
        {   
                rewrite ^/(.*)$ http://test.com/$1 permanent;
        }   
}
3.1.2 建立新的訪問目錄及檔案
[[email protected]LNMP ~]# mkdir -p /data/wwwroot/test.com/1/

[[email protected]LNMP ~]# echo "This file is in the 2nd directory of the root-directoy of site test.com" > /data/wwwroot/test.com/1/test.html
3.1.2 語法檢查、重新整理配置
[[email protected] ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

[[email protected] ~]# nginx -s reload

3.2 驗證

3.2.1 curl 驗證
  • 直接用 test.com域名進行訪問,報200
[[email protected] ~]# curl -x 192.168.1.100:80 test.com/1/test.html -I
HTTP/1.1 200 OK
Server: nginx/1.12.2
Date: Thu, 05 Jul 2018 06:33:14 GMT
Content-Type: text/html
Content-Length: 72
Last-Modified: Thu, 05 Jul 2018 06:31:20 GMT
Connection: keep-alive
ETag: "5b3dbb38-48"
Accept-Ranges: bytes
  • test1.com域名進行訪問,能夠正確訪問到所需的檔案,但是報301
[[email protected] ~]# curl -x 192.168.1.100:80 test1.com/1/test.html -I
HTTP/1.1 301 Moved Permanently
Server: nginx/1.12.2
Date: Thu, 05 Jul 2018 06:33:23 GMT
Content-Type: text/html
Content-Length: 185
Connection: keep-alive
Location: http://test.com/1/test.html
3.2.2 瀏覽器驗證(需修改hosts檔案)
  • 直接用 test.com域名進行訪問,報200
  • test1.com域名進行訪問,能夠正確訪問到所需的檔案,但是報301

4. Nginx 訪問日誌

4.1 日誌格式

變數 含義
$remote_addr 客戶端IP(公網IP)
$http_x_forwarded_for 代理伺服器的IP
$time_local 伺服器本地時間
$host 訪問主機名(域名)
$request_uri 訪問的url地址
$status 狀態碼
$http_referer referer
$http_user_agent user_agent

4.2 配置

4.2.1 檢視 nginx.conf 中設定了哪些日誌格式
## 可以看到有一種日誌格式叫做“combined_realip”
[[email protected] ~]# grep -A2 "log_format" /usr/local/nginx/conf/nginx.conf
    log_format combined_realip '$remote_addr$http_x_forwarded_for [$time_local]'
    ' $host "$request_uri" $status'
    ' "$http_referer" "$http_user_agent"';
4.2.2 在 vhost 的配置檔案中去採用這種日誌格式
[root@LNMP ~]# vim /usr/local/nginx/conf/vhost/test.com.conf 

server
{
        listen 80; 
        server_name test.com test1.com test2.com; 
        index index.html;
        root /data/wwwroot/test.com;

        ## 加入下行,指定日誌種類、日誌位置及檔名、日誌格式
        access_log /tmp/nginx_access.log combined_realip; 

        if ($host != 'test.com')
        {   
                rewrite ^/(.*)$ http://test.com/$1 permanent;
        }   
}
4.2.3 語法檢查、重新整理配置
[[email protected] ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

[[email protected] ~]# nginx -s reload

4.3 驗證

4.3.1 curl 驗證
  • 使用 curl 進行訪問
[[email protected] ~]# curl -x 192.168.1.100:80 test1.com/1/test.html
<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.12.2</center>
</body>
</html>
  • 檢視日誌
[root@LNMP ~]# tail -1 /tmp/nginx_access.log 
192.168.1.100 - [05/Jul/2018:15:52:59 +0800] test1.com "/1/test.html" 301 "-" "curl/7.29.0"
4.3.2 瀏覽器驗證

為了能夠看到 referer ,我們可以採取修改網頁原始碼的方式

  • 用IE開啟百度首頁,按【F12】鍵,選擇【DOM資源管理器】,選擇【選擇元素】(滑鼠圖案)

  • 點選一個網頁上的元素(比如【新聞】),DOM資源管理器將定位到該元素的原始碼

  • 修改該元素原始碼的 href 為我們測試的域名

  • 滑鼠點選已經修改過的元素(【新聞】),此時將跳轉到我們的測試域名,且 referer 為百度

  • 檢視日誌

[[email protected] ~]# tail -2 /tmp/nginx_access.log 
192.168.1.1 - [05/Jul/2018:15:49:40 +0800] test1.com "/1/test.html" 301 "https://www.baidu.com/" "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko"
192.168.1.1 - [05/Jul/2018:15:49:40 +0800] test.com "/1/test.html" 200 "https://www.baidu.com/" "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko"

5. Nginx 日誌切割

預設情況下,日誌是存在一個檔案內的,該日誌檔案會不斷變大,且會存放所有歷史的日誌。後期會很難定位日誌中某一日期的日誌,且較難刪除費日誌。所以我們需要採取手段,讓日誌檔案按照時間自行拆分成一個一個的小檔案

5.1 編輯指令碼

[[email protected] ~]# vim /usr/local/bin/nginx_log_rotate.sh 

#! /bin/bash
d=`date -d "-1 day" +%Y%m%d`   #設定日誌檔案的字尾
logdir="/tmp/"      #指定日誌所在目錄
nginx_pid="/usr/local/nginx/logs/nginx.pid"  #指定nginx_pid,與nginx.conf中的保持一致
cd $logdir
for log in `ls *.log`
do
mv $log $log-$d  #將以 .log 結尾的檔案,重新命名為以日期結尾
done
/bin/kill -HUP `cat $nginx_pid`                           

5.2 設定 cron 任務

[root@LNMP ~]# crontab -e

0 0 * * * /bin/bash /usr/local/sbin/nginx_log_rotate.sh

6. 靜態檔案不記錄日誌和過期時間

~每個頁面的載入都會訪問大量的檔案,每個檔案的訪問都會記錄一條日誌,這樣會使日誌量急劇增加。所以需要採取方法,讓對某些特定型別的檔案的訪問不產生日誌;

~瀏覽器瀏覽網頁時,會快取網站的靜態檔案,那快取下來的檔案能保留多久,在 Apache 上可以定義

6.1 配置

6.1.1 修改 vhost 配置檔案
[root@LNMP ~]# vim /usr/local/nginx/conf/vhost/test.com.conf 

server
{
        listen 80; 
        server_name test.com test1.com test2.com; 
        index index.html;
        root /data/wwwroot/test.com;
        access_log /tmp/nginx_access.log combined_realip;

        if ($host != 'test.com')
        {   
                rewrite ^/(.*)$ http://test.com/$1 permanent;
        }   


        ## 加入如下兩塊程式碼
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$  #匹配以圖片字尾結尾的檔案
        {   
                expires 7d;                         # 設定過期時間
                access_log off;                     # 設定不記錄日誌
        }   

        location ~ .*\.(js|css)$                    # 匹配以 js、css 為字尾的檔案
        {   
                expires 12h;                        # 設定過期時間
                access_log off;                     # 設定不記錄日誌
        }   
}
6.1.2 語法檢查、重新整理配置
[[email protected] ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

[[email protected] ~]# nginx -s reload

6.2 驗證

  • 先裝個 lrzsz,傳個圖片到站點

  • 使用瀏覽器訪問 test.html

  • 使用瀏覽器訪問圖片

  • 檢視日誌(不會有訪問圖片的相關日誌)

## 僅有訪問 html 檔案的日誌
[root@LNMP 1]# tail /tmp/nginx_access.log
192.168.1.1 - [05/Jul/2018:16:30:07 +0800] test.com "/1/test.html" 200 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko"

7. Nginx 防盜鏈

7.1 修改 vhost 配置檔案

[root@LNMP ~]# vim /usr/local/nginx/conf/vhost/test.com.conf 

        ## 在 server 塊中,增加如下 location 子塊,同時也做到對圖片的 expire 及 不記錄日誌的設定
        location ~* ^.+\.(gif|jpg|png|swf|flv|rar|zip|doc|pdf|gz|bz2|jpeg|bmp|xls)$
        {   
                expires 7d; 
                valid_referers none blocked server_names*.test.com;
                if ($invalid_referer)
                {   
                        return 403;
                }   
                access_logoff;
        }   

        ## 註釋掉先前配置的對於圖片的 expire 及 不記錄日誌的相關配置
#       location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$
#       {   
#               expires 7d; 
#               access_log off;
#       }   

7.2 語法檢查、重新整理配置

[[email protected] ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

[[email protected] ~]# nginx -s reload

8. Nginx 訪問控制

8.1 根據目錄進行訪問控制

8.1.1修改 vhost 配置檔案
[root@LNMP ~]# vim /usr/local/nginx/conf/vhost/test.com.conf 

        ## 在 server 塊中,增加如下 location 子塊
        location /admin/
        {   
                allow 192.168.1.100;
                allow 127.0.0.1;
                deny all;
        }   
8.1.2 建立測試目錄及檔案
[[email protected]LNMP ~]# mkdir /data/wwwroot/test.com/admin/
[[email protected]LNMP ~]# echo "test" > /data/wwwroot/test.com/admin/1.html
8.1.3 語法檢查、重新整理配置
[[email protected] ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

[[email protected] ~]# nginx -s reload
8.1.4 驗證
  • 在本機上訪問 admin 目錄
[root@LNMP ~]# ip add | grep 1.100
    inet 192.168.1.100/24 brd 192.168.1.255 scope global noprefixroute ens33
[root@LNMP ~]# curl -x 192.168.1.100:80 test.com/admin/1.html
test
  • 在另一臺 IP 為 192.168.1.3 的主機上訪問 admin 目錄
[[email protected] ~]# ip add | grep 192
    inet 192.168.1.3/24 brd 192.168.1.255 scope global noprefixroute ens33
## 訪問其他目錄,返回200    
[[email protected] ~]# curl -x 192.168.1.100:80 test.com/index.html -I
HTTP/1.1 200 OK
Server: nginx/1.12.2
Date: Fri, 06 Jul 2018 03:04:18 GMT
Content-Type: text/html
Content-Length: 77
Last-Modified: Thu, 05 Jul 2018 06:13:14 GMT
Connection: keep-alive
ETag: "5b3db6fa-4d"
Accept-Ranges: bytes

## 訪問 admin 目錄,返回 403
[[email protected] ~]# curl -x 192.168.1.100:80 test.com/admin/1.html -I
HTTP/1.1 403 Forbidden
Server: nginx/1.12.2
Date: Fri, 06 Jul 2018 03:04:21 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive

8.2 根據正則進行訪問控制

8.2.1 修改 vhost 配置檔案
[root@LNMP ~]# vim /usr/local/nginx/conf/vhost/test.com.conf 


        ## 在 server 塊中,增加如下 location 子塊
        location ~ .*(abc|image)/.*\.html$  # 匹配  ***abc/****.html 檔案
        {   
            deny all;   # 拒絕所有人訪問
        }   
8.2.2 建立測試目錄及檔案
[root@LNMP ~]# mkdir /data/wwwroot/test.com/abc/


[root@LNMP ~]# vim /data/wwwroot/test.com/abc/aaa.html 

This is aaa.html which is in the abc directory
8.2.3 語法檢查、重新整理配置
[[email protected] ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

[[email protected] ~]# nginx -s reload
8.2.4 驗證
## 訪問其他目錄的檔案
[[email protected] ~]# curl -x 192.168.1.100:80 test.com/index.html -I
HTTP/1.1 200 OK
Server: nginx/1.12.2
Date: Fri, 06 Jul 2018 03:13:40 GMT
Content-Type: text/html
Content-Length: 77
Last-Modified: Thu, 05 Jul 2018 06:13:14 GMT
Connection: keep-alive
ETag: "5b3db6fa-4d"
Accept-Ranges: bytes

## 訪問 abc 目錄下的檔案
[[email protected] ~]# curl -x 192.168.1.100:80 test.com/abc/aaa.html -I
HTTP/1.1 403 Forbidden
Server: nginx/1.12.2
Date: Fri, 06 Jul 2018 03:13:47 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive

8.3 對 user_agent 進行訪問控制

8.3.1 修改 vhost 配置檔案
[root@LNMP ~]# vim /usr/local/nginx/conf/vhost/test.com.conf 

        ## 在 server 塊中,增加以下 if 語句
        if ($http_user_agent ~ 'Spider/3.0|YoudaoBot|chocolee')
        {   
                return 403;
        }   
8.3.2 語法檢查、重新整理配置
[[email protected] ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

[[email protected] ~]# nginx -s reload
8.3.3 驗證
  • 使用 chocolee 作為 user_agnet 進行訪問,返回 403
[[email protected] ~]# curl -A "chocolee" -x 192.168.1.100:80 test.com -I
HTTP/1.1 403 Forbidden
Server: nginx/1.12.2
Date: Fri, 06 Jul 2018 05:43:32 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive
  • 將 chocolee 去掉一個 e 再試一次,返回 200
[[email protected] ~]# curl -A "chocole" -x 192.168.1.100:80 test.com -I
HTTP/1.1 200 OK
Server: nginx/1.12.2
Date: Fri, 06 Jul 2018 05:43:38 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/5.6.30

9. Nginx 開啟 php 解析

9.1 測試

9.1.1 在 vhost 站點下放置 php 測試檔案
[[email protected] ~]# vim /data/wwwroot/test.com/index.php 

<?php
phpinfo();
?>
9.1.2 curl 訪問測試(直接顯示原始碼)
[[email protected] ~]# curl -x 192.168.1.100:80 test.com/index.php
<?php
phpinfo();
?>
9.1.3 瀏覽器訪問測試(直接要求下載檔案)

9.2 配置

9.2.1 編輯 vhost 配置檔案
[root@LNMP ~]# vim /usr/local/nginx/conf/vhost/test.com.conf 

        ## 在 server 塊中,加入以下 location 程式碼子塊
        location ~ \.php$
        {   
                include fastcgi_params;
                fastcgi_pass unix:/tmp/php-fcgi.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME /data/wwwroot/test.com$fastcgi_script_name;
        }   
9.2.2 語法檢查、重新整理配置
[[email protected] ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

[[email protected] ~]# nginx -s reload

9.3 驗證

9.3.1 curl 驗證
[[email protected] ~]# curl -x 192.168.1.100:80 test.com/index.php
<?php
phpinfo();
?>
9.3.2 瀏覽器訪問 php 檔案,能夠正常解析

10. Nginx 代理

代理伺服器的功能是可以代理區域網絡的個人計算機來向因特網取得網頁或其他資料的一種服務, 由於代理取得的資料可以儲存一份在代理伺服器上,因此以往有類似『假象加速』的功能!不過,目前網路頻寬已經比以前好很多, 因此代理伺服器倒是很少使用在這方面。取而代之的是區域網絡『高階防火牆』的角色!這裡的『高階』指的是 OSI 七層協議裡面的高層,因為代理伺服器是用在應用層上的一種防火牆方式,不像 iptables 是用在網路、傳輸層。

10.1 配置

10.1.1 編輯單獨的 proxy.conf 檔案
[[email protected] tmp]# vim /usr/local/nginx/conf/vhost/proxy.conf

server
{
        listen 8080; 
        server_name www.pc6.com;
        access_log /tmp/proxy.log;

        location /
        {   
                proxy_pass http://27.159.76.229/;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }   
}
10.1.2 語法檢查、重新整理配置
[[email protected] ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

[[email protected] ~]# nginx -s reload

10.2 驗證

10.2.1 curl 驗證
## 不通過代理進行訪問
[root@LNMP tmp]# curl www.pc6.com/robots.txt
User-agent:*
Disallow:/*.asp
Disallow:/*.php
Disallow:/file/dl*
Disallow:/js/jf/
Disallow:/comment*
## 通過代理伺服器 192.168.1.100 的 8080 埠,訪問 www.pc6.com
[root@LNMP tmp]# curl -x 192.168.1.100:8080 www.pc6.com/robots.txt ; date
User-agent:*
Disallow:/*.asp
Disallow:/*.php
Disallow:/file/dl*
Disallow:/js/jf/
Disallow:/comment*

Fri Jul  6 15:16:00 CST 2018


## 檢視是否產生日誌
[root@LNMP tmp]# tail /tmp/proxy.log 
192.168.1.100 - - [06/Jul/2018:15:16:00 +0800] "GET HTTP://www.pc6.com/robots.txt HTTP/1.1" 200 104 "-" "curl/7.29.0"
10.2.2 瀏覽器驗證
  • IE 設定代理

  • 訪問 www.pc6.com

    相關推薦

    第二 LNMP

    目錄 1. 預設虛擬主機 2. Nginx 使用者認證 3. Nginx 域名重定向 4. Nginx 訪問日誌 5. Nginx 日誌切割 6. 靜態檔案不記錄日誌和過期時間 7. N

    第二章 NoSQL

    21.9 redis介紹 21.10 redis安裝 daemonize yes 表示redis為後臺啟動,終端繼續做其他事情logfile "/var/log/redis.log" 定義redis的日誌路徑dir /data/redis 定義red

    、字典:字典的遍歷

    文章目錄 (一)、如何遍歷字典所有的鍵-值對 (二)、如何遍歷字典中所有的鍵 (三)、如何遍歷字典所有的值 (四)、如何按照順序遍歷字典所有鍵 (

    第二章 NoSQL

    21.1 NoSQL介紹 21.2 memcached介紹 資料結構簡單(k-v),資料存放在記憶體裡。memcached 不支援持久化,資料落地。每當memcached服務重啟或者重啟伺服器,資料就會丟失。但可以定時來備份來讓資料落地 2

    第二章 Shell程式設計

    20.16 shell中的函式(上) $0 取指令碼的名稱   $# 取當前指令碼的引數 20.17 shell中的函式(下) 網絡卡名冒號後面記得加空格 20.18 shell中的陣列

    斯坦福大學-自然語言處理入門 筆記 第二 問答系統2

    一、問答系統中的總結(summarization) 目標:產生一個摘要文字包含那些對使用者重要和相關的資訊 總結的應用領域:任何文件的摘要和大綱,郵件摘要等等 根據總結的內容,我們可以把總結分為兩類: 單文件總結:給出一個單一文件的摘要、大綱、標題

    Linux入門第二天——基本命令入門

    路徑 span pan 系統命令 文件 參數 linux入門 作用 知識 一、文件搜索命令   1.文件搜索命令:locate   速度很快(具體見Linux工具網址的對比),註意無法找到新建的文件(原理暫不展開)   帥選規則:   實例:

    Go語言學習筆記: 切片slice

    操作 容量 方括號 一個 組類型 學習 中學 slice 修改 Go語言學習筆記十一: 切片(slice) 切片這個概念我是從python語言中學到的,當時感覺這個東西真的比較好用。不像java語言寫起來就比較繁瑣。不過我覺得未來java語法也會支持的。 定義切片 切片可以

    大數據入門第二天——scala入門scala基礎

    alt turn class 推斷 inf 循環 轉換 使用 mda 一、基礎語法   1.變量類型      // 上表中列出的數據類型都是對象,也就是說scala沒有java中的原生類型。在scala是可以對數字等基礎類型調用方法的。   2.變量聲明&mdas

    大數據入門第二二天——spark自定義分區、排序與查找

    get buffer arr clas ron arm scala mut all 一、自定義分區   1.概述     默認的是Hash的分區策略,這點和Hadoop是類似的,具體的分區介紹,參見:https://blog.csdn.net/high2011/arti

    大數據入門第二四天——SparkStreaming2與flume、kafka整合

    RM ESS 依賴 mep sock flume-ng bject 整合 master 前一篇中數據源采用的是從一個socket中拿數據,有點屬於“旁門左道”,正經的是從kafka等消息隊列中拿數據! 主要支持的source,由官網得知如下:

    第二 yum 更換國內源及下載rpm包、源碼包的安裝

    20180419一、yum更換國內源 1、下截: wget http://mirrors.163.com/.help/CentOS7-Base-163.repo 或者用curl -O 命令下載,然後刪除/etc/yum.repos.d/CentOS-Base.repo這個文件或更名。把CentOS7-Base

    C++筆記 第二 物件的構造順序---狄泰學院

    如果在閱讀過程中發現有錯誤,望評論指正,希望大家一起學習,一起進步。 學習C++編譯環境:Linux 第二十一課 物件的構造順序 問題:C++中的類可以定義多個物件,那麼物件構造的順序是怎樣的? 1.物件的構造順序一 對於 區域性物件 當程式執行流到達物件的定義語句時進行

    Python-資料結構與演算法、字典對映——基於兩種不同的底層實現

    保證一週更兩篇吧,以此來督促自己好好的學習!程式碼的很多地方我都給予了詳細的解釋,幫助理解。好了,幹就完了~加油! 宣告:本python資料結構與演算法是imooc上liuyubobobo老師java資料結構的python改寫,並添加了一些自己的理解和新的東西,liuyubobobo

    第二章 Shell程式設計

    20.27 分發系統介紹 20.28 expect指令碼遠端登入 #! /usr/bin/expect set host "192.168.93.128" set passwd "123456" spawn ssh [email protected]$host expect

    第二章 Shell程式設計

    20.1 Shell指令碼介紹 20.2 Shell指令碼結構和執行 20.3 date命令用法 Y年 m月 d日 [[email protected] shell]# date +%Y%m%d 20181026 H小時 M分鐘 S秒&nb

    第二預習筆記

    第二十一課預習任務 12.7 預設虛擬主機 12.8 Nginx使用者認證 12.9 Nginx域名重定向 12.10 Nginx訪問日誌 12.11 Nginx日誌切割 12.12 靜態檔案不記錄日誌和過期時間 12.13 Nginx防盜鏈 12.14 Nginx訪問控制

    Scala入門到精通——第二節 型別引數

    本節主要內容 Ordering與Ordered特質 上下文界定(Context Bound) 多重界定 型別約束 1. Ordering與Ordered特質 在介紹上下文界定之前,我們對scala中的Ordering與Ordered之間的關聯與區別

    Scala入門到精通——第二三節 高階型別

    本節主要內容 中置型別(Infix Type) 存在型別 函式型別 抽象型別 關於語法糖的問題,在講解程式語言時,我們常常聽到“語法糖”這個術語,在百度百科中,它具有如下定義: 語法糖(Syntactic Sugar),也叫糖衣語法, 是英國電腦科學家彼得·約翰

    javaweb基礎第二:session

    大綱:       session簡介 session工作原理 session的建立 session的使用 session時效 session失效