Nginx反向 Proxy和proxy_cache緩衝搭建CDN伺服器(1)

來源:互聯網
上載者:User

碰到問題:
移動使用者訪問web伺服器www.osyunwei.com很慢
解決辦法:
1、在移動機房放置一台nginx反向 Proxy伺服器
2、通過網域名稱DNS智能解析,所有移動使用者訪問www.osyunwei.com時解析到nginx反向 Proxy伺服器
3、nginx反向 Proxy伺服器與web伺服器之間採用專線串連

說明:
1、web伺服器
線路:電信
IP:192.168.21.129
網域名稱:www.osyunwei.com
2、nginx反向 Proxy伺服器
線路:移動
系統:CentOS 6.2
IP:192.168.21.164
vi /etc/hosts #編輯,在檔案最後添加下面一行
192.168.21.129 www.osyunwei.com
3、用戶端
線路:移動
系統:Windows 7
IP:192.168.21.130
C:\Windows\System32\drivers\etc\hosts #用記事本開啟,在檔案最後添加下面一行
192.168.21.164 www.osyunwei.com


###################以下操作在nginx反向 Proxy伺服器上配置###################
1、關閉SELinux

   vi /etc/selinux/config
   #SELINUX=enforcing     #注釋掉
   #SELINUXTYPE=targeted  #注釋掉
   SELINUX=disabled  #增加
   :wq  儲存,關閉。
   shutdown -r now重啟系統
2、開啟防火牆80連接埠
   vi /etc/sysconfig/iptables
   添加下面的內容
   -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
   /etc/init.d/iptables restart  #重啟防火牆使配置生效
3、安裝編譯工具
    系統營運  www.osyunwei.com  溫馨提醒:qihang01原創內容©著作權,轉載請註明出處及原文連結
    yum install wget  make gcc gcc-c++ zlib-devel openssl openssl-devel pcre-devel gd  kernel keyutils  patch perl
4 、系統約定
    軟體原始碼包存放位置:/usr/local/src
    源碼包編譯安裝位置:/usr/local/軟體名字
5、下載軟體
  cd /usr/local/src  #進入目錄
一)、下載nginx目前穩定版)
         wget http://nginx.org/download/nginx-1.0.12.tar.gz
二)、下載pcre  支援nginx偽靜態)
         wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.21.tar.gz
二)、下載ngx_cache_purge清除指定URL緩衝)
         wget http://labs.frickle.com/files/ngx_cache_purge-1.5.tar.gz
6、安裝pcre
   cd /usr/local/src
   mkdir /usr/local/pcre    #建立安裝目錄
   tar  zxvf pcre-8.21.tar.gz
   cd pcre-8.21
   ./configure  --prefix=/usr/local/pcre   #配置
   make
   make install
7、安裝 nginx
   groupadd  www   #添加www組
   useradd -g www www -s /bin/false   #建立nginx運行賬戶www並加入到www組,不允許www使用者直接登入系統    
   cd /usr/local/src
   tar  zxvf  ngx_cache_purge-1.5.tar.gz
   tar  zxvf nginx-1.0.12.tar.gz
   cd nginx-1.0.12
   ./configure --prefix=/usr/local/nginx  --user=www --group=www  --with-http_stub_status_module --with-openssl=/usr/ --with-pcre=/usr/local/src/pcre-8.21  --add-module=../ngx_cache_purge-1.5
   注意:--with-pcre=/usr/local/src/pcre-8.21指向的是源碼包解壓的路徑,而不是安裝的路徑,否則會報錯
   make   #編譯
   make install   #安裝
   /usr/local/nginx/sbin/nginx    #啟動nginx
   chown www.www -R /usr/local/nginx/html   #設定目錄所有者
   chmod 700 -R /usr/local/nginx/html    #設定目錄許可權


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.