<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    176142998

      BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
      116 Posts :: 0 Stories :: 45 Comments :: 0 Trackbacks

    Nginx作為一個后起之秀,他的迷人之處已經(jīng)讓很多人都投入了他的懷抱。配置簡單,實現(xiàn)原理簡單。做一個負載平衡的再好不過了。

    其原理:

    簡單介紹一下他的安裝及配置過程

    官方網(wǎng)站
    http://wiki.codemongers.com/Main

    一、依賴的程序

    1. gzip module requires zlib library
    2. rewrite module requires pcre library
    3. ssl support requires openssl library

    二、安裝
    ./configure
    make
    make install

    默認安裝的路徑是/usr/local/nginx

    更多的安裝配置
    ./configure --prefix=/usr/local/nginx
    --with-openssl=/usr/include (啟用ssl)
    --with-pcre=/usr/include/pcre/ (啟用正規(guī)表達式)
    --with-http_stub_status_module (安裝可以查看nginx狀態(tài)的程序)
    --with-http_memcached_module (啟用memcache緩存)
    --with-http_rewrite_module (啟用支持url重寫)


    三、啟動及重啟
    啟動:nginx
    重啟:kill -HUP `cat /usr/local/nginx/logs/nginx.pid`
    測試配置文件:nginx -t

    簡單吧,安裝,啟動都比較方便。

    四、配置文件
    http://wiki.codemongers.com/NginxFullExample

    #運行用戶
    user nobody nobody;
    #啟動進程
    worker_processes 5;
    #全局錯誤日志及PID文件
    error_log logs/error.log notice;
    pid logs/nginx.pid;
    #工作模式及連接數(shù)上限
    events {
    #工作模式有:select(標準模式),poll(標準模式),kqueue(高效模式,適用FreeBSD 4.1+, OpenBSD 2.9+, NetBSD 2.0 and MacOS X),
    #epoll(高效模式,本例用的。適用Linux 2.6+,SuSE 8.2,),/dev/poll(高效模式,適用Solaris 7 11/99+, HP/UX 11.22+ (eventport), IRIX 6.5.15+ 和 Tru64 UNIX 5.1A+)
    use epoll;
    worker_connections 1024;
    }
    #設(shè)定http服務器,利用它的反向代理功能提供負載均衡支持
    http {
    #設(shè)定mime類型
    include conf/mime.types;
    default_type application/octet-stream;
    #設(shè)定日志格式
    log_format main '$remote_addr - $remote_user [$time_local] '
    '"$request" $status $bytes_sent '
    '"$http_referer" "$http_user_agent" '
    '"$gzip_ratio"';
      log_format download    '$remote_addr - $remote_user [$time_local] '
    '"$request" $status $bytes_sent '
    '"$http_referer" "$http_user_agent" '
    '"$http_range" "$sent_http_content_range"';
      #設(shè)定請求緩沖
    client_header_buffer_size 10k;
    large_client_header_buffers 4 4k;

    #開啟gzip模塊,要求安裝gzip 在運行./config時要指定
    gzip on;
    gzip_min_length 1100;
    gzip_buffers 4 8k;
    gzip_types text/plain;
    output_buffers 1 32k;
    postpone_output 1460;

    #設(shè)定訪問日志
    access_log logs/access.log main;
    client_header_timeout 3m;
    client_body_timeout 3m;
    send_timeout 3m;
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;

    #設(shè)定負載均衡的服務器列表
    upstream backserver {
    #weigth參數(shù)表示權(quán)值,權(quán)值越高被分配到的幾率越大
    #本例是指在同一臺服務器,多臺服務器改變ip即可
    server 127.0.0.1:8081 weight=5;
    server 127.0.0.1:8082;
    server 127.0.0.1:8083;
    }
      #設(shè)定虛擬主機,默認為監(jiān)聽80端口,改成其他端口會出現(xiàn)問題
    server {
    listen 80;
    server_name test.com www.test.com;
    charset utf8;
    #設(shè)定本虛擬主機的訪問日志
    access_log logs/test.com.log main;
    #如果訪問 /images/*, /js/*, /css/* 資源,則直接取本地文件,不用轉(zhuǎn)發(fā)。但如果文件較多效果不是太好。
    location ~ ^/(images|js|css)/ {
    root /usr/local/testweb;
    expires 30m;
    }

    #對 "/" 啟用負載均衡
    location / {
    proxy_pass http://backserver;
    proxy_redirect off;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    client_max_body_size 10m;
    client_body_buffer_size 128k;
    proxy_connect_timeout 90;
    proxy_send_timeout 90;
    proxy_read_timeout 90;
    proxy_buffer_size 4k;
    proxy_buffers 4 32k;
    proxy_busy_buffers_size 64k;
    proxy_temp_file_write_size 64k;
    }
    #設(shè)定查看Nginx狀態(tài)的地址,在運行./config 要指定,默認是不安裝的。
    location /NginxStatus {
    stub_status on;
    access_log on;
    auth_basic "NginxStatus";
    #是否要通過用戶名和密碼訪問,測試時可以不加上。conf/htpasswd 文件的內(nèi)容用 apache 提供的 htpasswd 工具來產(chǎn)生即可
    #auth_basic_user_file conf/htpasswd;
    }
    }
    posted on 2010-11-25 21:15 飛飛 閱讀(191) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導航:
     
    主站蜘蛛池模板: 亚洲情XO亚洲色XO无码| 久别的草原电视剧免费观看| 人禽杂交18禁网站免费| 亚洲国产精品综合一区在线| xxxxwww免费| 成人亚洲国产va天堂| 无码少妇一区二区浪潮免费| 亚洲卡一卡二卡乱码新区| 毛片免费全部播放一级| 亚洲AV无码AV男人的天堂不卡| 在线观看免费亚洲| 黄色三级三级三级免费看| 亚洲日本中文字幕一区二区三区| 中文字幕在线视频免费| 亚洲免费视频网站| 波多野结衣免费在线| 亚洲国产精品无码久久九九大片 | 亚洲精品免费视频| 亚洲福利一区二区精品秒拍| 亚洲免费福利在线视频| 亚洲国产成人精品无码区二本| 国产免费怕怕免费视频观看| 亚洲免费视频一区二区三区| 亚洲高清视频在线观看| 嘿嘿嘿视频免费网站在线观看| 四虎亚洲精品高清在线观看| 国产乱子伦精品免费无码专区| 久久久久久久久久免免费精品| 亚洲人成网址在线观看| 毛片在线看免费版| 有码人妻在线免费看片| 亚洲一卡2卡三卡4卡有限公司| 日本一区二区三区免费高清 | 99精品热线在线观看免费视频 | 久久精品国产精品亚洲| 蜜桃成人无码区免费视频网站 | 91大神在线免费观看| 亚洲日韩精品无码专区| 亚洲精品乱码久久久久久久久久久久| 亚洲免费一级视频| 污污的视频在线免费观看|