nginx設定靜態資源 跳轉 到cdn 記錄

2021-10-23 17:30:24 字數 1688 閱讀 9384

rewriteengine on

# '-s' (is regular file, with size)

# '-l' (is symbolic link)

# '-d' (is directory)

# 'ornext|or' (or next condition)

# 'nocase|nc' (no case)

# 'last|l' (last rule)

# 'qsa' 追加請求字串

rewritecond %% !-s

rewritecond %% !-l

rewritecond %% !-f

rewriterule ^(.*)$ [nc,l]

設定檔案不存在時 直接302到線上

location ~ .*$

}

坑點1 

if 後面必須有空格

正則{}太難使用了

location ~ (.+)$

\.[a-z.] 取出主網域名稱

if ( $host ~* ([a-z0-9-][a-z0-9-][a-z0-9-]+\.[a-z][a-z][a-z]?(\.[a-z][a-z]+)?)$)

#排除 ip暫時沒有關聯

#if ($host ~* [0-9]+\.[0-9]+$ )

#檔案是否存在

if ( -d "$paths/$host" )

#排除 跳轉到目的地

if ($host = $tohost)

#return 200 "path: $path

path1: $path1

pathpp: $pathpp host: $host";

#排除 seo和瀏覽器主入口檔案

if ( $pathpp ~* .*(sitemap\.xml|sitemap\.txt|robots\.txt|.+\.html|.+\.htm|.+\.php|/|/[^./?#]+)([?#].*)?$)

#判斷是否需要生成資料夾

if ($path != "")

#return 200 "path: $path

path1: $path1

pathpp: $pathpp host: $host";

#檔案是否存在

if ( -d $path1 )

}

反向**的使用

location ^~ /xhxx 

#這裡是考試系統需要呼叫的介面

Nginx 靜態資源快取設定

在開發除錯web的時候,經常會碰到因瀏覽器快取 cache 而經常要去清空快取或者強制重新整理來測試的煩惱,提供下apache不快取配置和nginx不快取配置的設定。在常用的快取設定裡面有兩種方式,都是使用add header來設定 分別為cache control和pragma。nginx loc...

iOS跳轉到設定介面

定位服務設定介面 nsurl url nsurl urlwithstring prefs root location services 這樣就可以跳到系統設定的定位服務介面啦!我們繼續看幾個列子。facetime設定介面 nsurl url nsurl urlwithstring prefs roo...

跳轉到系統設定頁面

如何跳到指定的設定介面,例如設定wifi的時候,想直接跳到wifi設定介面。在url types新增 乙個叫prefs的url schemes 複製 2.新增這段 把下面的bundle identifier替換為相應的字段即可 複製 3.對應的字段 蜂窩網路 prefs root mobile da...