成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

使用Nginx怎么實現(xiàn)一個非套路鏡像站

使用Nginx怎么實現(xiàn)一個非套路鏡像站?相信很多沒有經(jīng)驗的人對此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個問題。

創(chuàng)新互聯(lián)公司專注于甘州網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供甘州營銷型網(wǎng)站建設(shè),甘州網(wǎng)站制作、甘州網(wǎng)頁設(shè)計、甘州網(wǎng)站官網(wǎng)定制、微信小程序服務(wù),打造甘州網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供甘州網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。

方案一

做了如下配置:

1

2

3

4

5

6

7

8

location ^~ /book-c/

{

 proxy_pass http://akaedu.github.io/book/;

 proxy_redirect off;

 proxy_http_version 1.1;

 proxy_set_header Upgrade $http_upgrade;

 proxy_set_header Connection "upgrade";

}

瀏覽了下,都 ok,但是有幾點不太好

  • 如果以后我發(fā)現(xiàn)類似的書很好,都要增加一個 nginx 配置。

  • 如果原始網(wǎng)站完全無法訪問了,我這邊也掛了,不能緩存到我本地服務(wù)器

  • 我想修改網(wǎng)頁內(nèi)容也不太好操作,比如我想加上原作者的版權(quán)和原始訪問地址說明等。

完全采集過來,我也懶得寫腳本去跑,最終走上了下面這段踩坑路。

嘗試改進

1

rewrite ^/book-(.*?)/  /index.php?m=Book&a=show&book=$1 last;

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

class BookAction extends Action{

 private $uri;

 public function show(){

 $book = $_GET['book'];

 if (!method_exists($this,$book)){

  $this->error404();

 }

 try{

  $this->$book();

 }catch (Exception $e){

  $this->error404();

 }

 }

 

 /**

 * http://akaedu.github.io/book/

 */

 private function c(){

 $baseUrl = "http://akaedu.github.io/book/";

 $url = $baseUrl.$this->uri;

 echo file_get_contents($url);

 }

}

又遇到了一個問題,當我訪問 https://mengkang.net/book-c/styles.css 則無法 rewrite 匹配到了。

原因是 nginx 優(yōu)先匹配了

1

2

3

4

location ~ .*\.(js|css)?$

{

 expires 12h;

}

方案二

添加一條

?

1

2

3

4

location ~ /book-.*?/

{

 rewrite ^/book-(.*?)/ /index.php?m=Book&a=show&book=$1 last;

}

location ^~ 不支持正則的,所以沒法用

采坑小記

如果是使用的 location ~ /book-.*/ ,根據(jù)正則就是貪婪模式,那么

/upload/otherpic71/47891.jpg

匹配到的就是 /book-c/images/ ,也就是說rewrite里面的 $1 就是 c/images ,這樣和我們的預(yù)期相悖的。

故障:無法匹配到 css 文件

?

1

2

3

4

5

6

7

8

9

$ wget -S https://mengkang.net/book-c/styles.css -O /dev/null

--2018-02-01 13:13:36-- https://mengkang.net/book-c/styles.css

Resolving mengkang.net... 203.195.188.207

Connecting to mengkang.net|203.195.188.207|:443... connected.

HTTP request sent, awaiting response...

 HTTP/1.1 200 OK

 Server: nginx

 Date: Thu, 01 Feb 2018 05:13:38 GMT

 Content-Type: text/html; charset=UTF-8

所有內(nèi)容的輸出默認都是 text/html ,那么也就是我需要對文件的后綴判斷咯。 感覺自己給自己挖坑,不如直接采集得了

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

<?php

class BookAction extends Action{

 const BOOK_SAVE_DIR = "/data/book/";

 private $uri;

 private $baseUrl;

 private $book;

 private $bookname;

 public function show(){

 $book = $_GET['book'];

 $this->book = $book;

 $this->uri = str_replace("/book-{$book}/","",$_SERVER['REQUEST_URI']);

 if (!method_exists($this,$book)){

  $this->error404();

 }

 try{

  $this->$book();

 }catch (Exception $e){

  $this->error404();

 }

 }

 /**

 * http://akaedu.github.io/book/

 */

 private function c(){

 $this->baseUrl = "http://akaedu.github.io/book/";

 $url = $this->baseUrl.$this->uri;

 $this->output($url);

 }

 private function output($url){

 $ext = pathinfo($url,PATHINFO_EXTENSION);

 if (!$ext) {

  $url = $url."/index.html";

  $ext = "html";

 }

 switch ($ext){

  case "css":

  header("Content-Type: text/css; charset=UTF-8");

  break;

  default:

  header("Content-Type: text/html; charset=UTF-8");

  break;

 }

 // 如果已經(jīng)緩存

 $filename = self::BOOK_SAVE_DIR.$this->book."/".str_replace($this->baseUrl,"",$url);

 if (file_exists($filename)){

  $data = file_get_contents($filename);

 }else{

  $data = file_get_contents($url);

  $dir = dirname($filename);

  if (!file_exists($dir)){

  mkdir($dir,755,true);

  }

  file_put_contents($filename,$data);

 }

 // 增加原始版權(quán)說明

 echo $data;

 }

}

看完上述內(nèi)容,你們掌握使用Nginx怎么實現(xiàn)一個非套路鏡像站的方法了嗎?如果還想學到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!

原文鏈接:http://mengkang.net/1152.html

網(wǎng)頁名稱:使用Nginx怎么實現(xiàn)一個非套路鏡像站
文章網(wǎng)址:http://jinyejixie.com/article38/pshcsp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供域名注冊、企業(yè)建站移動網(wǎng)站建設(shè)、搜索引擎優(yōu)化、品牌網(wǎng)站制作手機網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

綿陽服務(wù)器托管