正則表達式-~^排錯

首先給大家看下錯誤日誌:

[root@VM_0_6_centos myfile]# tail -f /var/log/nginx/error.log
2019/07/31 18:32:39 [error] 17672#0: *2291 open() "/home/myfile/fhtml/cross/download/index.htm" failed (2: No such file or directory), client: 183.247.191.35, server: localhost, request: "GET /download/index.htm HTTP/1.1", host: "129.204.225.131:82"
2019/07/31 18:32:43 [error] 17672#0: *2291 open() "/home/myfile/fhtml/cross/download/index.html" failed (2: No such file or directory), client: 183.247.191.35, server: localhost, request: "GET /download/index.html HTTP/1.1", host: "129.204.225.131:82"
2019/07/31 18:32:48 [error] 17672#0: *2291 "/home/myfile/fhtml/cross/download/index.html" is not found (2: No such file or directory), client: 183.247.191.35, server: localhost, request: "GET /download/ HTTP/1.1", host: "129.204.225.131:82"
2019/07/31 18:33:44 [error] 17672#0: *2291 open() "/home/myfile/fhtml/cross/download/index.html" failed (2: No such file or directory), client: 183.247.191.35, server: localhost, request: "GET /download/index.html HTTP/1.1", host: "129.204.225.131:82"
2019/07/31 18:33:47 [error] 17672#0: *2291 open() "/home/myfile/fhtml/cross/download/index.html.gz" failed (2: No such file or directory), client: 183.247.191.35, server: localhost, request: "GET /download/index.html.gz HTTP/1.1", host: "129.204.225.131:82"
2019/07/31 18:33:50 [error] 17672#0: *2291 open() "/home/myfile/fhtml/cross/download/index.html.gz" failed (2: No such file or directory), client: 183.247.191.35, server: localhost, request: "GET /download/index.html.gz HTTP/1.1", host: "129.204.225.131:82"
2019/07/31 18:34:51 [notice] 18075#0: signal process started
2019/07/31 18:34:57 [error] 18076#0: *2294 open() "/home/myfile/fhtml/cross/download" failed (2: No such file or directory), client: 183.247.191.35, server: localhost, request: "GET /download HTTP/1.1", host: "129.204.225.131:82"
2019/07/31 18:35:06 [error] 18076#0: *2294 open() "/home/myfile/txt/download/error.txt" failed (2: No such file or directory), client: 183.247.191.35, server: localhost, request: "GET /download/error.txt HTTP/1.1", host: "129.204.225.131:82"
2019/07/31 18:35:16 [error] 18076#0: *2294 open() "/home/myfile/txt/download/error.txt" failed (2: No such file or directory), client: 183.247.191.35, server: localhost, request: "GET /download/error.txt HTTP/1.1", host: "129.204.225.131:82"

 request: "GET /download HTTP/1.1", host: "129.204.225.131:82"
2019/07/31 18:35:06 [error] 18076#0: *2294 open() "/home/myfile/txt/download/error.txt" failed (2: No such file or directory), client: 183.247.191.35, server: localhost, request: "GET /download/error.txt HTTP/1.1", host: "129.204.225.131:82"
2019/07/31 18:35:16 [error] 18076#0: *2294 open() "/home/myfile/txt/download/error.txt" failed (2: No such file or directory), client: 183.247.191.35, server: localhost, request: "GET /download/error.txt HTTP/1.1", host: "129.204.225.131:82"
2019/07/31 18:43:11 [notice] 19445#0: signal process started
2019/07/31 18:43:23 [error] 19446#0: *2298 open() "/home/myfile/txt/download/error.txt" failed (2: No such file or directory), client: 183.247.191.35, server: localhost, request: "GET /download/error.txt HTTP/1.1", host: "129.204.225.131:82"
2019/07/31 18:43:31 [error] 19446#0: *2298 open() "/home/myfile/images/download/校服.jpg" failed (2: No such file or directory), client: 183.247.191.35, server: localhost, request: "GET /download/%E6%A0%A1%E6%9C%8D.jpg HTTP/1.1", host: "129.204.225.131:82"
2019/07/31 18:43:38 [error] 19446#0: *2298 open() "/home/myfile/images/download/校服.jpg" failed (2: No such file or directory), client: 183.247.191.35, server: localhost, request: "GET /download/%E6%A0%A1%E6%9C%8D.jpg HTTP/1.1", host: "129.204.225.131:82"



2019/07/31 18:45:13 [error] 19750#0: *2301 open() "/home/myfile/images/download/校服.jpg" failed (2: No such file or directory), client: 183.247.191.35, server: localhost, request: "GET /download/%E6%A0%A1%E6%9C%8D.jpg HTTP/1.1", host: "129.204.225.131:82"

``server {
    listen       82;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /home/myfile/fhtml/cross/;
        index  index.html index.htm;
    }

    location ~.*\.(jpg|gif|png)$ {
        gzip on;
        gzip_http_version 1.1;
        gzip_min_length 1;
        gzip_comp_level 5;
        gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
        root   /home/myfile/images;
        #index  index.html index.htm;
    }

    location ~.*\.(txt|xml)$ {
        gzip on;
        gzip_http_version 1.1;
        gzip_comp_level 8;
        gzip_types *;
        root   /home/myfile/txt;
        #index  index.html index.htm;
    }

    location ~ ^/download/ {
        gzip_static off;
        tcp_nopush on;
        root   /home/myfile/;#注意一個問題,匹配的時候,這個地址在前面,download在後面。
        #index  index.html index.htm;
    }

是這樣,之前一直通過downloadURL訪問圖片和txt一直出錯,因爲,匹配的時候,先匹配了上面的,所以,肯定出錯。後來改爲訪問docx文件,正確。
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章