iT邦幫忙

1

關於purge 404的問題

安裝了purge後,也確定purge的套件有加載進nginx裡面,但配置nginx反代理後,經過測試呈現404,稍微Google了一下,也無法解決,不曉得大家有沒有遇到類似的狀況

nginx反代理配置

upstream proxy {

        server  172.16.16.8:80;
}
proxy_cache_path /var/cache/proxy/

                levels=1:2 keys_zone=proxy:10m

                max_size=1g inactive=1h;

server {
    listen      80 default;
    server_name www.scott.com;

    access_log  /var/log/nginx/proxy.access.log;
    error_log   /var/log/nginx/proxy.error.log;

    proxy_buffers 16 64k;
    proxy_buffer_size 128k;

    location / {

        proxy_pass  http://proxy;
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
        proxy_redirect off;

        proxy_set_header    Host            $host;
        proxy_set_header    X-Real-IP       $remote_addr;
        proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header    X-Forwarded-Proto https;
       proxy_set_header     X-Forwarded-Host $host;

      proxy_cache proxy;
       proxy_cache_key    $uri$is_args$args;

        proxy_cache_valid      200  1d;
        proxy_cache_use_stale  error timeout invalid_header updating http_500 http_502 http_503 http_504;


      location ~ /purge(/.*) {

                proxy_cache_purge  proxy$1$is_args$args;
                }
    }

}

nginx源端配置

server {
        listen 80;                      #port

        server_name www.scott.com;      #域名
        root /usr/share/nginx/html/web;  #路徑
        index index.html;                 #第一個開啟位置
}

測試方式

http://www.scott.com/purge

呈現結果是 ...

404 Not Found
nginx/1.16.1

看更多先前的討論...收起先前的討論...
stevejobs iT邦新手 5 級 ‧ 2020-04-06 04:49:49 檢舉
https://www.ryadel.com/en/nginx-purge-proxy-cache-delete-invalidate-linux-centos-7/
使用方式參考這邊上面
或restart你的nginx
或直接到主機用rm -rf /var/cache/proxy/*清除
也可用命令要清除,可以參考給你的網址,用curl的指令執行

或指定名稱比如:http://www.scott.com/purge/123.jpg
無法直接指定目錄,要帶上你要purge的檔案。

線上執行要限制可執行的ip。不是全開,上面給你的網址有範例
這台最好別放在外面,404錯誤都寫了,not found。你的這台cache主機最好放後面,就不用限ip了。
踏雪尋梅 iT邦研究生 5 級 ‧ 2020-04-06 10:20:53 檢舉
謝謝您,雖然目前問題仍未解決,稍微同步一下

curl http://www.scott.com/purge/index.html -I

結果

HTTP/1.1 404 Not Found
Date: Mon, 06 Apr 2020 02:19:07 GMT
Server: Apache
Accept-Ranges: bytes
Content-Type: text/html

----

問題是這台機器是乾淨的,沒裝過Apache,所以讓我有點納悶
froce iT邦大師 1 級 ‧ 2020-04-06 10:41:52 檢舉
就去檢查一下機器有沒有裝到啊,我知道用ubuntu有時候會莫名其妙安裝上去,cent我就不清楚了。
踏雪尋梅 iT邦研究生 5 級 ‧ 2020-04-06 10:50:19 檢舉
rpm -qa | grep httpd
httpd -v
-bash: httpd: command not found

確實查看沒有安裝相關 apache的東西 (雖然我不常用apache)
踏雪尋梅 iT邦研究生 5 級 ‧ 2020-04-06 11:27:35 檢舉
我修改成
curl http://172.16.16.11/purge/index.html -I
然後host 172.16.16.11 www.scott.com就正常了

HTTP/1.1 404 Not Found
Server: nginx/1.10.2
Date: Mon, 06 Apr 2020 03:27:07 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive
死狐狸 iT邦新手 5 級 ‧ 2020-04-06 11:28:24 檢舉
有確認過 www.scott.com 對應到的是你那台 ubuntu 的主機嗎?

正常的話,應該連入時會在 access.log 留下來訪記錄,有確認過 log 正常否?
踏雪尋梅 iT邦研究生 5 級 ‧ 2020-04-06 11:37:14 檢舉
確認access.log 正常,有從 反代理端到源端

172.16.16.11 - - [06/Apr/2020:11:36:06 +0800] "GET / HTTP/1.0" 200 11 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36" "172.16.16.99"

172.16.16.99 是我本機 Lan
死狐狸 iT邦新手 5 級 ‧ 2020-04-07 13:24:01 檢舉
所以你以 ip 的方式由 99 連 11 是開啟正常?

其實我是想問你以 99 連 11 跟 99 連 www.scott.com 都有會進入 access.log ?
如果你以外部 ip 連 www.scott.com 也有進入 access.log ?
踏雪尋梅 iT邦研究生 5 級 ‧ 2020-04-07 13:27:14 檢舉
我是再 .99 本機做 Host
172.16.16.11 www.scott.com
然後再透過 .11 反向代理到 .7 (源端)

.11 和 .7 都有 access.log訊息,並能正確訪問到 index.html index.js index.jpg
死狐狸 iT邦新手 5 級 ‧ 2020-04-07 13:40:05 檢舉
那你反向的 config 中的 upstream proxy 設定的「server 172.16.16."8":80」是?
踏雪尋梅 iT邦研究生 5 級 ‧ 2020-04-07 14:10:08 檢舉
哦不好意思,我弄太多機器,自己搞混了

server 172.16.16."8":80 是正確的,我上面打錯

.7 是我另一台的反代理端 (不同的安裝方式測試用,拍謝)
死狐狸 iT邦新手 5 級 ‧ 2020-04-07 14:27:06 檢舉
這樣我就覺得比較奇怪了…我反向做的比較少,經驗不足…

我在外部 www.scott.com/purge 404 後的 header 也是出現在 server: apache ,你那邊除了你,還有其他人也在管理其他的 web service 嗎,有沒有剛好也是用 apache,查查他們的 access.log 有沒有出現 /purge 是 404 的記錄,如果有出現…可能真的跳到別台去了
踏雪尋梅 iT邦研究生 5 級 ‧ 2020-04-07 14:58:05 檢舉
目前這台是我自己用的虛擬機,用Centos7 mini 安裝,檢查過無apache

然後你在虛擬機Host 172.16.16.11 www.scott.com

在測一次就會變成 nginx了

很怪
死狐狸 iT邦新手 5 級 ‧ 2020-04-08 00:45:23 檢舉
抱歉,可能沒講清楚,我的意思是說…www.scott.com 在你去設定 host 172.16.16.11 www.scott.com 之前,scott 是對應到哪一台?

我不確定你的環境是不是有分內外 dns ,我從外部看 scott 是對應到 45.40.x.x 的 ip ,那 apache 理論上是設定在 45.40.x.x 的這一台或其相關 mapping 到的主機上,未必就是 45.40.x.x:80 mapping 172.16.16.11:http

你在虛擬機設定 host 172.16.16.11 www.scott.com 只是強制讓你的虛擬機連 scott 時是連到 172.16.16.11 ,但這代表你虛擬機原本 scott 時,它並不會連到 11 的那台,那就應該是別台了。

所以,在假設你的 nginx config 是無誤的情況下,會不會你或你工作的環境或公司的 mis 有其他人也跟你一定在處理其他 web service 的反向代理或 mapping,所以 www.scott.com/purge 就是不會連到你的 11
死狐狸 iT邦新手 5 級 ‧ 2020-04-08 11:55:11 檢舉
忘了問,你在虛擬機設定 host 11 scott 後,網頁的header 是出現 server: nginx 了,但網頁開啟的結果是你要的嗎?
踏雪尋梅 iT邦研究生 5 級 ‧ 2020-04-08 15:19:46 檢舉
確定是出現 server: nginx ,網頁開啟,也是我想要的

另外上一個問題,因為我是在自己的電腦架設VM,確定不會被防火牆干擾到
死狐狸 iT邦新手 5 級 ‧ 2020-04-08 15:34:02 檢舉
ok,那我想應該就沒問題了?

只要你 www.scott.com -> 172.16.16.11 就 ok 了

抱歉,打擾你那麼久
stevejobs iT邦新手 5 級 ‧ 2020-04-10 01:24:58 檢舉
.11或.8
一定有apache。因為我現在還看的到
netstat -atunpl | grep 80

ps -aux | grep 80
我懷疑你的80被你的apache搶了
解決掉應該就行了。基本上你的nginx設定沒問題。
死狐狸,也很棒的幫你解答了很多基礎功
踏雪尋梅 iT邦研究生 5 級 ‧ 2020-04-10 11:57:55 檢舉
好 我試試 感謝您
踏雪尋梅 iT邦研究生 5 級 ‧ 2020-04-24 15:55:18 檢舉
補充:這部分其實我還沒完成,我暫時改用Script的方式去清Cache
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答