国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > WEB服務 > 正文

Nginx實現泛域名CDN節點配置

2020-05-27 13:25:03
字體:
來源:轉載
供稿:網友

   如何使用Nginx泛域名解析+反向代理+靜態資源緩存呢?

  1.安裝nginx,安裝過程不再贅述,記得帶上pcre、gzip、sub、status這幾個模塊,另外如果想開通在線清理緩存功能,需要安裝ngx_cache_purge這個第三方模塊。

  2.刪除nginx.conf中默認的server段,此操作不做你會讓你抱憾終身。

  3.將以下代碼插入nginx.conf尾部,-t測試-s reload重啟即可。

 代碼如下  

#定義緩存的臨時目錄以及緩存存儲目錄 proxy_temp_path /data/temp; proxy_cache_path /data/cache levels=1:2 keys_zone=cache_one:32m inactive=1d max_size=3g; server {     listen 80;     #接收泛域名解析,務必保證在這之前沒有其他server段干擾。     server_name _;     root /tmp;     access_log off;

    #匹配出對應域名     if ( $host ~* (.*).(.*).(.*))     {         set $domain $1;     }

    location /         {         #定義所使用的緩存以及緩存的目錄結構。         proxy_cache cache_one;         proxy_cache_valid  200 304 12h;         proxy_cache_key $host$uri$is_args$args;         #下面這條灰常重要,告知upstream源服務器所要請求的域名是什么。         proxy_set_header Host $host;         proxy_set_header X-Real-IP $remote_addr;         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;         #把請求扔給upstream,然后等著領賞吧。         proxy_pass http://jp0129;         proxy_set_header Accept-Encoding "";         expires 1d;         }     location ~ .*.(php)?$         {         #動態請求不緩存         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_pass http://jp0129;         proxy_set_header Accept-Encoding "";         } } upstream  jp0129 {         server 106.187.51.139; }

  大功告成,根據自身情況上機器,每臺部署一個nginx即可,在域名管理中把vcs.xxx.com直接A記錄幾條輪詢,配合一個小腳本來實現檢測各個節點是否存活,節點宕掉就直接通過dnspod的api修改vcs.xxx.com的解析記錄,剔除無效節點即可。

  附一個Nginx下泛域名解析配置

  在Nginx下支持泛域名解析其實很簡單.只要在在編譯 Nginx的時候加上以下代碼即可

  --with-http_sub_module

  在配置nginx時:

 代碼如下  

server {

        # Replace this port with the right one for your requirements

        listen      80;#could also be 1.2.3.4:80

 

        # Multiple hostnames seperated by spaces.  Replace these as well.

        server_name  www.111cn.net *.你的域名.com;

        #Alternately: _ *

        root /PATH/TO/WEBROOT/$host;

        error_page  404              http://yourdomain.com/errors/404.html;

        access_log  logs/yourdomain.com.access.log;

        location / {

            root  /PATH/TO/WEBROOT/$host/;

            index  index.php;

        }

 

        # serve static files directly

        location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|html)$ {

            access_log        off;

            expires          30d;

        }

 

        location ~ .php$ {  

          # By all means use a different server for the fcgi processes if you need to  

          fastcgi_pass  127.0.0.1:YOURFCGIPORTHERE;

          fastcgi_index  index.php;

 

          fastcgi_param  SCRIPT_FILENAME  /PATH/TO/WEBROOT/$host/$fastcgi_script_name;

          fastcgi_param  QUERY_STRING    $query_string;

          fastcgi_param  REQUEST_METHOD  $request_method;

          fastcgi_param  CONTENT_TYPE    $content_type;

          fastcgi_param  CONTENT_LENGTH  $content_length;

          fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;

          fastcgi_param  REQUEST_URI        $request_uri;

          fastcgi_param  DOCUMENT_URI      $document_uri;

          fastcgi_param  DOCUMENT_ROOT      $document_root;

          fastcgi_param  SERVER_PROTOCOL    $server_protocol;

          fastcgi_param  REMOTE_ADDR        $remote_addr;

          fastcgi_param  REMOTE_PORT        $remote_port;

          fastcgi_param  SERVER_ADDR        $server_addr;

          fastcgi_param  SERVER_PORT        $server_port;

          fastcgi_param  SERVER_NAME        $server_name;

          fastcgi_intercept_errors on;

        }

 

        location ~ /.ht {

            deny  all;

        }

    }

  然后啟動nginx就可以實現泛域名解析了

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 虹口区| 德州市| 莲花县| 德清县| 江川县| 堆龙德庆县| 柏乡县| 大埔区| 榆林市| 大方县| 鲁山县| 福州市| 台中县| 利川市| 霍城县| 汕头市| 阜康市| 紫云| 环江| 昭苏县| 昆明市| 福海县| 北海市| 马山县| 合江县| 仁布县| 陇川县| 北辰区| 冀州市| 英山县| 荥阳市| 宁阳县| 金沙县| 彩票| 峨眉山市| 吉林市| 连州市| 错那县| 永宁县| 吴忠市| 普定县|