Nginx implementation of universal Domain name CDN node configuration

Source: Internet
Author: User

How to use nginx Pan domain name Resolution + Reverse proxy + static resource caching?

1. Installation Nginx, installation process no longer repeat, remember to bring Pcre, gzip, sub, status of these modules, in addition, if you want to open online cleaning cache function, you need to install Ngx_cache_purge this third-party module.

2. Delete the default server segment in nginx.conf, this action does not do you will make you regret for life.

3. Insert the following code into the nginx.conf tail, the-t test-s reload reboot.

The code is as follows

#定义缓存的临时目录以及缓存存储目录
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;
#接收泛域名解析, make sure that there are no other server segment disturbances before that.
server_name _;
root/tmp;
Access_log off;

#匹配出对应域名
if ($host ~* (. *). *). (.*))
{
Set $domain $;
}

    Location/
        {
         #定义所使用的缓存以及缓存的目录结构.
        Proxy_cache Cache_one;
        proxy_cache_valid  304 12h;
        proxy_cache_key $host $uri$is_args$args;
        #下面这条灰常重要 to tell upstream what the domain name is to be requested by the source server.
        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, and wait for a reward.
        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;
}

Success, according to their own situation on the machine, each deployment of a nginx can, In the domain name management of Vcs.xxx.com direct a record several polling, with a small script to achieve the detection of the survival of each node, the node is down directly through the Dnspod API to modify the vcs.xxx.com of the analytic record, eliminate the invalid node.

With a nginx under the pan domain name resolution configuration

It's really easy to support a nginx under the sun. Just add the following code to compile the Nginx

--with-http_sub_module

When configuring Nginx:

The code is as follows

server {

# Replace This port with the ' right one ' for your requirements

Listen #could also be 1.2.3.4:80

# multiple hostnames seperated by spaces. Replace these as.

Server_Name www.111cn.net *. your domain name. 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;

}

}

And then start Nginx to implement the universal domain name resolution.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.