服務項目:網站建設、仿站、程序開發(fā)、APP開發(fā)設計、移動網站開發(fā)設計、企業(yè)網站設計、電子商務網站開發(fā)、網站維護、網站推廣、UX/UI 、HTML5、CSS3、JS / Jquery ...
四川浚??萍加邢薰?></a></div>
                    <div   id=四川???萍加邢薰? title=
四川???萍加邢薰?(開發(fā)設計官網)TEL : 15308000360 / QQ : 38585404

您的位置:首頁 > 技術經驗 > 服務器 > 正文

Nginx反向代理+DNS輪詢+IIS 千萬PV 百萬IP 雙線 網站架構案例
技術支持服務電話:15308000360 【7x24提供運維服務,解決各類系統(tǒng)/軟硬件疑難技術問題】

Nginx  ("engine x") 是一個高性能的 HTTP 和反向代理服務器,也是一個 IMAP/POP3/SMTP 代理服務器。 Nginx 是由 Igor Sysoev 為俄羅斯訪問量第二的 Rambler.ru 站點開發(fā)的,它已經在該站點運行超過兩年半了。Igor 將源代碼以類BSD許可證的形式發(fā)布。

Nginx 的中文維基:http://wiki.codemongers.com/NginxChs

Nginx 超越 Apache 的高性能和穩(wěn)定性,使得國內使用 Nginx 作為 Web 服務器的網站也越來越多,其中包括新浪博客、新浪播客、網易新聞、騰訊網、搜狐博客等門戶網站頻道,六間房、56.com等視頻分享網站,Discuz!官方論壇、水木社區(qū)等知名論壇,盛大在線、金山逍遙網等網絡游戲網站,豆瓣、人人網、YUPOO相冊、金山愛詞霸、迅雷在線等新興Web 2.0網站。

在高并發(fā)連接的情況下,Nginx是Apache服務器不錯的替代品。Nginx同時也可以作為7層負載均衡服務器來使用。根據(jù)我的測試結果,Nginx 0.8.46 + PHP 5.2.14 (FastCGI) 可以承受3萬以上的并發(fā)連接數(shù),相當于同等環(huán)境下Apache的10倍。

根據(jù)我的經驗,4GB內存的服務器+Apache(prefork模式)一般只能處理3000個并發(fā)連接,因為它們將占用3GB以上的內存,還得為系統(tǒng)預留1GB的內存。我曾經就有兩臺Apache服務器,因為在配置文件中設置的MaxClients為4000,當Apache并發(fā)連接數(shù)達到3800時,導致服務器內存和Swap空間用滿而崩潰。

而這臺 Nginx 0.8.46 + PHP 5.2.14 (FastCGI) 服務器在3萬并發(fā)連接下,開啟的10個Nginx進程消耗150M內存(15M*10=150M),開啟的64個php-cgi進程消耗1280M內存(20M*64=1280M),加上系統(tǒng)自身消耗的內存,總共消耗不到2GB內存。如果服務器內存較小,完全可以只開啟25個php-cgi進程,這樣php-cgi消耗的總內存數(shù)才500M。

在3萬并發(fā)連接下,訪問Nginx 0.8.46 + PHP 5.2.14 (FastCGI) 服務器的PHP程序,仍然速度飛快。下圖為Nginx的狀態(tài)監(jiān)控頁面,顯示的活動連接數(shù)為28457(關于Nginx的監(jiān)控頁配置,會在本文接下來所給出的Nginx配置文件中寫明):

 

lampw3c教程網 請稍等 圖片正在加載中

 

lampw3c教程網 請稍等 圖片正在加載中

 


為什么Nginx的性能要比Apache高得多?這得益于Nginx使用了最新的epoll(Linux 2.6內核)和kqueue(freebsd)網絡I/O模型,而Apache則使用的是傳統(tǒng)的select模型。目前Linux下能夠承受高并發(fā)訪問的Squid、Memcached都采用的是epoll網絡I/O模型。

處理大量的連接的讀寫,Apache所采用的select網絡I/O模型非常低效。下面用一個比喻來解析Apache采用的select模型和Nginx采用的epoll模型進行之間的區(qū)別:

假設你在大學讀書,住的宿舍樓有很多間房間,你的朋友要來找你。select版宿管大媽就會帶著你的朋友挨個房間去找,直到找到你為止。而epoll版宿管大媽會先記下每位同學的房間號,你的朋友來時,只需告訴你的朋友你住在哪個房間即可,不用親自帶著你的朋友滿大樓找人。如果來了10000個人,都要找自己住這棟樓的同學時,select版和epoll版宿管大媽,誰的效率更高,不言自明。同理,在高并發(fā)服務器中,輪詢I/O是最耗時間的操作之一,select和epoll的性能誰的性能更高,同樣十分明了。

以上信息我無恥的從張宴博客中拷貝過來,張宴博客http://blog.s135.com/,下面開始正題

某公司有一站點,一天IP 430W,PV 3100W,之前采用5臺 DELL R610 做NLB,系統(tǒng)2008 IIS7.5.每天高峰期時都不堪重負.會出現(xiàn)以下情況

1:遠程登陸巨慢無比
2:遠程登陸系統(tǒng)后無法操作,表現(xiàn)為鼠標移動緩慢,操作延時,系統(tǒng)呆滯.
3:CPU長期在80%以上,內存消耗極高
4:....
經過部門討論后決定采用Nginx反向代理的架構替代目前不堪重負的站點.拓撲圖如下

 

lampw3c教程網 請稍等 圖片正在加載中

 

硬件:
前端采用2臺DELL M420刀片,虛擬4臺Centos5.8跑Nginx反向代理.
后端依舊采用5臺服務器,不過從硬件上也升級到DELL M420 2008系統(tǒng) IIS7.5

網絡結構:
Nginx
電信 192.168.0.1 192.168.0.2
聯(lián)通 192.168.1.1 192.168.1.2

2008 IIS7.5
電信 192.168.0.10 192.168.0.11 192.168.0.13 192.168.0.14 192.168.0.15
聯(lián)通 192.168.1.10 192.168.1.11 192.168.1.13 192.168.1.14 192.168.1.15

域名xxx.com通過DNS輪詢到 Nginx前端,再根據(jù)你的配置甩向不同upstream

新架構部署好后能明顯感覺整個站點打開都飛快,后端完全無壓力狀態(tài),這還并沒有開啟Nginx自帶的Cache.
現(xiàn)在這套架構每天承載百萬IP 千萬PV的訪問量 如圖
AWStats 統(tǒng)計結果

lampw3c教程網 請稍等 圖片正在加載中

 

單臺Centos CPU圖

lampw3c教程網 請稍等 圖片正在加載中

 


安裝步驟:
一:
2臺宿主機虛擬成4臺這個步驟就略過,網上教程一大把.在這里我們每臺分配2個cpu共8個核心,內存6G,硬盤100G.
系統(tǒng)要求:Linux 2.6+ 內核,本文中的Linux操作系統(tǒng)為CentOS 5.8 64位)
系統(tǒng)為最精簡安裝文本界面,系統(tǒng)安裝好后配置系統(tǒng).

#修改系統(tǒng)DNS

rm -rf /etc/resolv.conf
touch /etc/resolv.conf
echo -ne "nameserver 114.114.114.114\nnameserver 114.114.115.115\nsearch localdomain" >>/etc/resolv.conf

#修改系統(tǒng)源

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget http://mirrors.163.com/.help/CentOS5-Base-163.repo
cp CentOS5-Base-163.repo /etc/yum.repos.d/

#yum 升級安裝,根據(jù)需求自己行刪除

yum install -y lrzsz gcc gcc-c++ make flex autoconf automake vixie-cron libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel kernel-devel wget patch ntp libevent m4 zip unzip gd gd-devel file libtool-libs gmp-devel pspell-devel mod_perl-devel parted apr-util readline-devel sysstat vim* popt-devel patch openssh-clients net-snmp net-snmp-devel net-snmp-utils net-snmp-libs

#設置ssh下 SecureCRT標簽顯示為帳號@IP

touch /etc/sysconfig/bash-prompt-xterm
vim  /etc/sysconfig/bash-prompt-xterm
#添加以下一行

echo -ne "\e]2;${USER}@$(/sbin/ifconfig eth0|grep 'inet addr'|sed -e 's/^.*inet addr:\(.*\) Bcast.*$/\1/')\a"

#設置term類型是screen時(命令screen進入新窗口時)標簽顯示內容, 和xterm一樣

cp /etc/sysconfig/bash-prompt-xterm /etc/sysconfig/bash-prompt-screen

#設置term類型不是xterm和screen時標簽顯示內容, 也和xterm一樣

cp /etc/sysconfig/bash-prompt-xterm /etc/sysconfig/bash-prompt-default

#給予可執(zhí)行權限

chmod +x /etc/sysconfig/bash-prompt-*

#修改文件句柄數(shù)為65535,默認系統(tǒng)為1024

echo "session required /lib64/security/pam_limits.so" >>/etc/pam.d/login
echo -ne "
* soft nofile 65534
* hard nofile 65534
" >>/etc/security/limits.conf

#添加iptables

rm -rf /etc/sysconfig/iptables
touch /etc/sysconfig/iptables
cat << EOF >> /etc/sysconfig/iptables
此段加入你的iptables規(guī)則

EOFservice iptables restart

#根據(jù)硬件優(yōu)化Linux性能

cat << EOF >> /etc/sysctl.conf
# Add#開啟SYN Cookies,當出現(xiàn)SYN等待隊列溢出時,啟用cookies來處理
net.ipv4.tcp_syncookies = 1#表示SYN隊列的長度,默認為1024,加大隊列長度為8192,可以容納更多等待連接的網絡連接數(shù)。
net.ipv4.tcp_max_syn_backlog = 65536#每個網絡接口接收數(shù)據(jù)包的速率比內核處理這些包的速率快時,允許送到隊列的數(shù)據(jù)包的最大數(shù)目
net.core.netdev_max_backlog =  262144net.ipv4.tcp_fin_timeout = 30

#當keepalive起用的時候,TCP發(fā)送keepalive消息的頻度。缺省是2小時
net.ipv4.tcp_keepalive_time = 1200
#redis設置
net.core.somaxconn = 262144
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_timestamps = 0

#參數(shù)的值決定了內核放棄連接之前發(fā)送SYN+ACK包的數(shù)量
net.ipv4.tcp_synack_retries = 2

#在內核放棄建立連接之前發(fā)送SYN包的數(shù)量
net.ipv4.tcp_syn_retries = 2

#啟用timewait快速回收
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 94500000 915000000 927000000
#系統(tǒng)中最多有多少個TCP套接字不被關聯(lián)到任何一個用戶文件句柄上。這個限制僅僅是為了防止簡單的DoS攻擊,不能過分依靠它或者人為地減小這個值,更應該增加這個值(如果增加了內存之后)
net.ipv4.tcp_max_orphans = 3276800

#允許系統(tǒng)打開的端口范圍
net.ipv4.ip_local_port_range = 1024  65535
#增加系統(tǒng)文件描述符限制
fs.file-max = 65535

#允許更多的PIDs (減少滾動翻轉問題); may break some programs 32768
kernel.pid_max = 65536

# 增加TCP最大緩沖區(qū)大小
net.ipv4.tcp_rmem = 4096 4096 16777216
net.ipv4.tcp_wmem = 4096 4096 16777216
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.eth0.send_redirects = 0
net.ipv4.conf.all.send_redirects = 0

#2012-8-30
#net.ipv4.ip_conntrack_max=1048576
#net.ipv4.netfilter.ip_conntrack_max=1048576
net.ipv4.netfilter.ip_conntrack_tcp_timeout_time_wait=120
net.ipv4.netfilter.ip_conntrack_tcp_timeout_close_wait=60
net.ipv4.netfilter.ip_conntrack_tcp_timeout_fin_wait=120
net.ipv4.neigh.default.gc_thresh1=10240
net.ipv4.neigh.default.gc_thresh2=40960
net.ipv4.neigh.default.gc_thresh3=81920

#timewait的數(shù)量
net.ipv4.tcp_max_tw_buckets =6000
EOF

#刷新sysctl.conf

/sbin/sysctl -p

#禁用ipv6

echo -ne "alias net-pf-10 off\noptions ipv6 disable=1" >>/etc/modprobe.conf
/sbin/chkconfig --level 35 ip6tables off

#關閉 selinux

sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config

#將同步好的時間寫到CMOS里

sed -i 's#SYNC_HWCLOCK=no#SYNC_HWCLOCK=yes#' /etc/sysconfig/ntpd

#設置同步時間

echo "0 6 * * * /usr/sbin/ntpdate 192.168.0.172;/sbin/hwclock -w; >/dev/null 2>&1" >>/var/spool/cron/root
service crond restart

#修改系統(tǒng)啟動級別

sed -i 's/id:5:initdefault:/id:3:initdefault:/g' /etc/inittab

#禁止ctrl+alt+del

sed -i "s/ca::ctrlaltdel:\/sbin\/shutdown -t3 -r now/#ca::ctrlaltdel:\/sbin\/shutdown -t3 -r now/"  /etc/inittab

二:
獲取相關開源程序:
Nginx 官方當前穩(wěn)定版為 nginx-1.2.4 ,我測試環(huán)境使用版本為nginx-1.3.3
pcre-8.31
nginx_upstream_check_module
ngx_cache_purge-1.6
請自行從網絡下載

安裝步驟:

#新建WWW用戶組和WWW用戶

groupadd www
useradd -g www www -s /bin/false

#創(chuàng)建相應的目錄

mkdir -p /data/html/www
mkdir -p /data/proxy_temp_dir
mkdir -p /data/proxy_cache_path
mkdir -p /data/logs
chown -R www:www /data/proxy_cache_path
chown -R www:www /data/proxy_temp_dir
chown -R www:www /data/html/
chown -R www:www /data/logs

#安裝內核和openssl

yum -y install openssl-devel kernel-devel

#安裝Pcre

tar zxvf pcre-8.31.tar.gz
cd pcre-8.31
./configure --prefix=/usr/local/pcre
make
make install

#安裝nginx

tar zxvf ngx_cache_purge-1.6.tar.gz
tar zxvf nginx-1.3.3.tar.gz
tar zxvf nginx_upstream_check_module.tar.gz
cd nginx-1.3.3
patch -p1 < /root/nginx_keepalived_install/nginx_upstream_check_module/check_1.2.2+.patch
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_realip_module --with-http_gzip_static_module --with-openssl=/usr/ --with-pcre=/root/nginx_keepalived_install/pcre-8.31 --add-module=/root/nginx_keepalived_install/ngx_cache_purge-1.6 --add-module=/root/nginx_keepalived_install/nginx_upstream_check_module
make
make install

cp /root/nginx_keepalived_install/cut_nginx_log.sh /usr/local/nginx/sbin/
chmod +x /usr/local/nginx/sbin/cut_nginx_log.sh
echo -ne "00 00 * * * /bin/bash  /usr/local/nginx/sbin/cut_nginx_log.sh" >>/var/spool/cron/root
service crond restart
chown -R www:www /usr/local/nginx/
cp /root/nginx_keepalived_install/nginx /etc/rc.d/init.d/
chmod +x /etc/rc.d/init.d/nginx
chkconfig nginx on

到這里Nginx安裝完畢,目前Nginx所有的配置都是默認配置,我貼下我案例中的NGINX配置,如有錯誤請大牛們指導.

Nginx.conf

user  www  www;
worker_processes 8;
worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;
worker_rlimit_nofile 204800;error_log  /data/logs/error.log;pid        logs/nginx.pid;events {
worker_connections  240800;
use epoll;
}http {
include   nginx_load_balance.conf;
#include    proxy.conf;
include       mime.types;
default_type  application/octet-stream;
server_names_hash_bucket_size 128;
#log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
#'$status $body_bytes_sent "$http_referer" '
#'"$http_user_agent" $http_x_forwarded_for';
#access_log  /data/logs/access.log  access;
sendfile        on;
tcp_nopush     on;
tcp_nodelay on;
server_tokens off;
keepalive_timeout 60;
client_header_buffer_size 4k;
#large_client_header_buffers 4 32k;
client_max_body_size 10m;
client_header_timeout  120s;
client_body_timeout    120s;
send_timeout           120s;
gzip  off;
gzip_min_length 1k;
gzip_buffers 4 16k;
output_buffers   1 512k;
postpone_output  1460;
#gzip_http_version 1.1;
gzip_comp_level 4;
gzip_types text/plain text/css text/javascript text/xml application/x-javascript application/xml application/xml+rss;
gzip_vary on;
server {
listen       80;
server_name  localhost;
location / {
rewrite ^ http://www.test.com$request_uri?;
#root   /data/html/www;
#index  index.html index.htm;
}
error_page  404              /data/html/www/404.html;
error_page   500 502 503 504  /50x.html;
location = /50x.html {
root   html;
}
location /status {
stub_status on;
access_log  off;
}
location /nstatus {
check_status;
access_log off;
#allow SOME.IP.ADD.RESS;
#deny all;
}
}
include  vhost/*.conf;
}

nginx_load_balance.conf

#1:默認為輪訓,每個請求按時間順序逐一分配到不同的后端服務器,如果后端服務器down掉,能自動剔除.
#2:weight,指定輪詢幾率,weight和訪問比率成正比,用于后端服務器性能不均的情況.
#3:ip_hash,每個請求按訪問ip的hash結果分配,這樣每個訪客固定訪問一個后端服務器,可以解決session的問題.
#4:fair,按后端服務器的響應時間來分配請求,響應時間短的優(yōu)先分配.
#5:url_hash,按訪問url的hash結果來分配請求,使每個url定向到同一個后端服務器,后端服務器為緩存時比較有效.
#check interval=3000 rise=2 fall=5 timeout=1000;
#check interval=3000 rise=2 fall=5 timeout=1000 type=ssl_hello;
#check interval=3000 rise=2 fall=5 timeout=1000 type=http;
#check_http_send "GET / HTTP/1.0\r\n\r\n";
#check_http_send "GET / HTTP/1.1\r\nHOST:\r\n\r\n";
#check_http_expect_alive http_2xx http_3xx http_4xx;
#interval檢測間隔時間,單位為毫秒,rsie請求2次正常的話,標記此realserver的狀態(tài)為up,fall表示請求5次都失敗的情況下,標記此realserver的狀態(tài)為down,timeout為超時時間,單位為毫秒。
upstream dx {
ip_hash;
server 192.168.0.11:80;
server 192.168.0.12:80;
server 192.168.0.13:80;
server 192.168.0.14:80;
server 192.168.0.15:80;
check interval=3000 rise=2 fall=8 timeout=3000 type=http;
check_http_send "GET / HTTP/1.0\r\n\r\n";
check_http_expect_alive http_2xx http_3xx http_4xx;
#server 192.168.0.30:80; backup;
}upstream lt {
ip_hash;
server 192.168.1.11:80;
server 192.168.1.12:80;
server 192.168.1.13:80;
server 192.168.1.14:80;
server 192.168.1.15:80;
check interval=3000 rise=2 fall=8 timeout=3000 type=http;
check_http_send "GET / HTTP/1.0\r\n\r\n";
check_http_expect_alive http_2xx http_3xx http_4xx;
#server 192.168.1.30:80; backup;
}

proxy.conf

proxy_temp_path   /data/proxy_temp_dir;   #指定臨時文件目錄
proxy_cache_path  /data/proxy_cache_path levels=1:2 keys_zone=cache_one:2000m inactive=1d max_size=1g;
client_body_buffer_size  512k; #增加緩沖區(qū)代理緩沖客戶端請求的最大字節(jié)數(shù)
proxy_connect_timeout    60;   #增加連接后端服務器超時時間
proxy_read_timeout       60;   #增加后端服務器響應請求超時時間
proxy_send_timeout       60;   #增加后端服務器發(fā)送數(shù)據(jù)超時時間
proxy_buffer_size        32k;   #增加代理請求緩存區(qū)大小
proxy_buffers           4 64k;  #增加
proxy_busy_buffers_size 128k;   #增加系統(tǒng)繁忙時可申請的proxy_buffers大小
proxy_temp_file_write_size 128k;  #增加proxy緩存臨時文件的大小
proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;   #增加故障轉移,如果后端的服務器返回502、504、執(zhí)行超時等錯誤,自動將請求轉發(fā)到upstream負載均衡池中的另一臺服務器,實現(xiàn)故障轉移。
proxy_cache cache_one;  #增加使用web緩存區(qū)cache_one

以上是Nginx配置,下面是vhost中網站配置
xxxx_com.conf

server
{
listen       192.168.0.1;
server_name  xxx.com;access_log  /data/logs/dx.log  dx;location /
{
proxy_next_upstream http_502 http_504 error timeout invalid_header;
# proxy_cache cache_one;
# proxy_cache_valid  200 304 12h;
# proxy_cache_key $host$uri$is_args$args;
proxy_set_header Host $http_host;
#proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_headers_hash_max_size 51200;
proxy_headers_hash_bucket_size 6400;proxy_pass http://dx;#if ($request_uri ~* "^/upload/") {
#add_header Cache-Control 'max-age=86400';
#}
location ~* \.(gif|jpg|jpeg|png|flv|swf|ico)$
{
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://dx;
add_header Cache-Control 'max-age=86400';
}
location ~* \.(js)$
{
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://dx;
add_header Cache-Control 'max-age=600';
}
#expires      -1;
add_header Cache-Control 'no-store, no-cache, must-revalidate';
add_header Pragma no-cache;
}
location ~ /purge(/.*)
{
allow            127.0.0.1;
allow            192.168.0.0/16;
deny            all;
#proxy_cache_purge    cache_one   $host$1$is_args$args;
}
location ~ .*\.(php|jsp|cgi|asp|aspx|flv|swf|xml)?$
{
proxy_set_header Host $http_host;
#proxy_set_header X-Forwarded-For  $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://dx;
}
}
server
{
listen       192.168.1.1;
server_name xxxx.com;
access_log  /data/logs/lt.log  lt;
location /
{
proxy_next_upstream http_502 http_504 error timeout invalid_header;
#proxy_cache cache_one;
#proxy_cache_valid  200 304 12h;
#proxy_cache_key $host$uri$is_args$args;
proxy_set_header Host $http_host;
#proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_headers_hash_max_size 51200;
proxy_headers_hash_bucket_size 6400;
proxy_pass http://lt;
#if ($request_uri ~* "^/upload/") {
#add_header Cache-Control 'max-age=86400';
#}
location ~* \.(gif|jpg|jpeg|png|flv|swf|ico)$
{
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://lt;
add_header Cache-Control 'max-age=86400';
}
location ~* \.(js)$
{
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://lt;
add_header Cache-Control 'max-age=600';
}
#expires      -1;
add_header Cache-Control 'no-store, no-cache, must-revalidate';
add_header Pragma no-cache;
}
location ~ /purge(/.*)
{
allow            127.0.0.1;
allow            192.168.0.0/16;
deny            all;
#proxy_cache_purge    cache_one   $host$1$is_args$args;
}
location ~ .*\.(php|jsp|cgi|asp|aspx|flv|swf|xml)?$
{
proxy_set_header Host $http_host;
#proxy_set_header X-Forwarded-For  $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://lt;
}
}

至此,一套完整的Nginx反向代理全部結束.


網站無法打開排查

1:ping域名看解析是否正常且是否連通.

2:配置本機Hosts指向后端單機IIS查看網站是否正常訪問.

3:檢查前端Nginx進程和端口是否存在,
ps -ef |grep nginx
netstat -an |grep 80

系統(tǒng)相關配置

Nginx
Nginx目錄/usr/local/nginx/
/usr/local/nginx/conf/nginx.conf Nginx主配置文件
/usr/local/nginx/conf/nginx_load_balance.conf Nginx反向代理輪詢配置文件
/usr/local/nginx/conf/proxy.conf Nginx緩存配置相關
/usr/local/nginx/conf/vhost/ Nginx虛擬主機配置目錄

Snmp
/etc/snmp/snmpd.conf

日志切割

/root/scripts/ 所有日志切割腳本都在這個目錄
crontab -l 列出計劃任務
crontab -e 編輯計劃任務

系統(tǒng)相關操作

Nginx
重啟Nginx service nginx restart
重載Nginx配置文件 service nginx reload
檢測Nginx配置語法是否正確 /usr/local/nginx/sbin/nginx -t
關閉Nginx service nginx stop
啟動Nginx service nginx start

Snmp
重啟Snmp service snmpd restart
關閉Snmp service snmpd stop
啟動Snmp service snmpd start



上一篇:nginx安裝第三方模塊的方法
下一篇:windows下安裝zookeeper

相關熱詞搜索:nginx iis