茫茫網海中的冷日 - 對這文章發表回應
茫茫網海中的冷日
         
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已!
 恭喜您是本站第 1674145 位訪客!  登入  | 註冊
主選單

Google 自訂搜尋

Goole 廣告

隨機相片
PIMG_00001.jpg

授權條款

使用者登入
使用者名稱:

密碼:


忘了密碼?

現在就註冊!

對這文章發表回應

發表限制: 非會員 可以發表

發表者: 冷日 發表時間: 2018/12/21 10:44:44
設定 nginx 為 reverse cache server

Nginx(發音同 engine x)是一款由俄羅斯程式設計師 Igor Sysoev 所開發輕量級的網頁伺服器、反向代理伺服器以及電子郵件(IMAP/POP3)代理伺服器。起初是供俄國大型的入口網站及搜尋引擎 Rambler(俄語:Рамблер)使用。此軟體 BSD-like 協定下發行,可以在 UNIX、GNU/Linux、BSD、Mac OS X、Solaris,以及 Microsoft Windows等作業系統中執行。
步驟
1.安裝 CentOS
請參考 http://www.snippetinfo.net/media/235
設定部分: http://www.snippetinfo.net/media/240

2.設定 yum
# vi /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

3.使用 yum 安裝 nginx
# yum install nginx
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror01.idc.hinet.net
 * extras: mirror01.idc.hinet.net
 * updates: mirror01.idc.hinet.net
nginx                                                                                                                                                     | 2.9 kB     00:00
nginx/primary_db                                                                                                                                          |  24 kB     00:00
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package nginx.x86_64 0:1.4.2-1.el6.ngx will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================================================================================================
 Package                                Arch                                    Version                                             Repository                              Size
=================================================================================================================================================================================
Installing:
 nginx                                  x86_64                                  1.4.2-1.el6.ngx                                     nginx                                  311 k

Transaction Summary
=================================================================================================================================================================================
Install       1 Package(s)

Total download size: 311 k
Installed size: 770 k
Is this ok [y/N]: y
Downloading Packages:
nginx-1.4.2-1.el6.ngx.x86_64.rpm                                                                                                                          | 311 kB     00:01
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : nginx-1.4.2-1.el6.ngx.x86_64                                                                                                                                  1/1
----------------------------------------------------------------------

Thanks for using NGINX!

Check out our community web site:
* http://nginx.org/en/support.html

If you have questions about commercial support for NGINX please visit:
* http://www.nginx.com/support.html

----------------------------------------------------------------------
  Verifying  : nginx-1.4.2-1.el6.ngx.x86_64                                                                                                                                  1/1

Installed:
  nginx.x86_64 0:1.4.2-1.el6.ngx

Complete!

4.建立 nginx所使用 的 cache 目錄
mkdir /var/nginx
mkdir /var/nginx/cache

5.設定 nginx.conf
其中 proxy_pass http://xxx.xxx.xxx.xxx; 要設定你要指向的 proxy ip
# vi /etc/nginx/nginx.conf

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {

    proxy_cache_path  /var/nginx/cache  levels=1:2    keys_zone=STATIC:10m
                                         inactive=24h  max_size=1g;
     client_max_body_size 10G;
     server {
        location / {
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass             http://xxx.xxx.xxx.xxx;
            proxy_set_header       Host $host;
            proxy_cache            STATIC;
            proxy_cache_valid      200  1d;
            proxy_cache_use_stale  error timeout invalid_header updating
                                   http_500 http_502 http_503 http_504;
        }
    }

    include /etc/nginx/conf.d/*.conf;
}

6.
如果要對應多站台的話
# vi /etc/nginx/nginx.conf

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {

    proxy_cache_path  /var/nginx/cache  levels=1:2    keys_zone=STATIC:10m
                                         inactive=24h  max_size=1g;

    client_max_body_size 10G;
    sendfile        on;
    tcp_nopush     on;

    keepalive_timeout  600;
    tcp_nodelay        on;


    upstream backend {
        server {your-backend-server1}:80;
        server {your-backend-server2}:80;
    }

    server {
        location / {
            add_header X-Proxy-Cache    $upstream_cache_status;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass                  http://backend;
            proxy_set_header            Host $host;

            proxy_cache_key             "$scheme$host$request_uri";
            proxy_cache                 STATIC;
            proxy_cache_valid           200  1d;
            proxy_cache_use_stale       error timeout invalid_header updating
                                        http_500 http_502 http_503 http_504;

            proxy_connect_timeout       6000;
            proxy_send_timeout          6000;
            proxy_read_timeout          6000;
            proxy_buffer_size           4k;
            proxy_buffers               4 32k;
            proxy_busy_buffers_size     64k;
            proxy_temp_file_write_size  64k;
            send_timeout                6000;
            proxy_buffering             off;
        }


        gzip on;
        gzip_min_length 1k;
        gzip_buffers 4 16k;
        #gzip_http_version 1.0;
        gzip_comp_level 2;
        gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php;
        gzip_vary off;
        gzip_disable "MSIE [1-6]\.";
    }

    include /etc/nginx/conf.d/*.conf;
}

7.啟動服務並設為自動啟動
# service nginx restart
# chkconfig nginx on


原文出處:設定 nginx 為 reverse cache server | 老洪的 IT 學習系統
內容圖示
url email imgsrc image code quote
樣本
bold italic underline linethrough   












 [詳情...]
validation picture

注意事項:
預覽不需輸入認證碼,僅真正發送文章時才會檢查驗證碼。
認證碼有效期10分鐘,若輸入資料超過10分鐘,請您備份內容後,重新整理本頁並貼回您的內容,再輸入驗證碼送出。

選項

Powered by XOOPS 2.0 © 2001-2008 The XOOPS Project|