|
|
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已! |
|
恭喜您是本站第 1729928
位訪客!
登入 | 註冊
|
|
|
|
發表者 |
討論內容 |
冷日 (冷日) |
發表時間:2018/12/21 10:44 |
- Webmaster

- 註冊日: 2008/2/19
- 來自:
- 發表數: 15773
|
- [轉貼]設定 nginx 為 reverse cache server
- 設定 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 學習系統
|
|
|
討論串
-
[轉貼]Nginx 在 windows 環境下的安裝與簡單配置 (冷日 (冷日), 2018/12/20 9:54)
-
[轉貼]Windows 下安裝配置 Nginx 詳解 (冷日 (冷日), 2018/12/20 10:01)
-
[轉貼]在windows 環境下的安裝、配置、使用以及設置為 windows 服務自啟動 (冷日 (冷日), 2018/12/20 10:24)
-
[轉貼]在 windows 環境下的安裝、配置、使用以及設置為 windows 服務自啟動 (冷日 (冷日), 2018/12/21 10:21)
-
[轉貼]Nginx Virtual Host 設定教學 (冷日 (冷日), 2018/12/21 10:29)
-
[轉貼]Nginx – 設定虛擬主機 (Virtual Host) 的方式 (冷日 (冷日), 2018/12/21 10:32)
-
[轉貼]多個 virtual host 共用一個 Nginx Site Config (冷日 (冷日), 2018/12/21 10:35)
-
[轉貼]CentOS 6 建立 Nginx Reverse Proxy (冷日 (冷日), 2018/12/21 10:39)
- »
[轉貼]設定 nginx 為 reverse cache server (冷日 (冷日), 2018/12/21 10:44)
-
[轉貼]Nginx 加上 SSL 設定 (reverse proxy mode) (冷日 (冷日), 2018/12/21 10:47)
-
[轉貼]老闆!來一個能支援 Socket.io 的 NGINX Reverse Proxy Server 吧! (冷日 (冷日), 2018/12/21 11:15)
|