**摘要:**nginx有很多很强大的功能,可以做web,可以做代理、可以做SLB、还可以做缓存CDN等等,这里记录以下做缓存时的配置。

Install package

  • yum.repo
1
wget http://mirrors.opencas.cn/epel/6/i386/epel-release-6-8.noarch.rpm
  • Install
1
yum install nginx-1.0.15-12.el6.x86_64

Service config

  • 配置:example one 创建cdn源站其端口为12345 在/etc/nginx/conf.d这个目录下添加一个cdn.conf的文件
 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
# The default server
server {
    listen       12345 default_server;
    server_name  _;
    #charset koi8-r;
    #access_log  logs/host.access.log  main;
    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;
    location / {
        root   /usr/share/nginx/cdn;
        index  index.html index.htm;
    }
    error_page  404              /404.html;
    location = /404.html {
        root   /usr/share/nginx/cdn;
    }
    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/cdn;
    }
    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}
    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}
  • start service
1
/etc/init.d/nginx start

check

  • 在/usr/share/nginx/cdn/下放个文件,for example:test

    在浏览器键入:http://service_ip:12345/test


ok,以上