日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

OpenResty Nginx負(fù)載均衡配置和虛擬服務(wù)器路由配置詳解

 復(fù)雜網(wǎng)絡(luò)621 2017-07-17


新段時間把自己的博客搬到了云服務(wù)器上、那么搭建環(huán)境就是必須的了、在搭建好環(huán)境之后、需要對Nginx進(jìn)行配置、其實是對OpenResty進(jìn)行配置、因為我部署的是OpenResty的服務(wù)器、OpenResty是一個基于Nginx與Lua的高性能Web平臺、最終其實還是在對Nginx進(jìn)行配置

畢竟我是將我的DD博客、DD記賬下載頁和一個App開發(fā)頁以及DD記賬的App接口都放到同一個服務(wù)器的、在此記錄下Nginx服務(wù)器nginx.conf的配置文件說明、希望對大家有用

#運行用戶
user dwtedx.com;    
#啟動進(jìn)程、通常設(shè)置成和cpu的數(shù)量相等
worker_processes  1;

#全局錯誤日志及PID文件
error_log  logs/error.log;
error_log  logs/error.log  notice;
error_log  logs/error.log  info;

pid        logs/nginx.pid;

#工作模式及連接數(shù)上限
events {
    #epoll是多路復(fù)用IO(I/O Multiplexing)中的一種方式
    #但是僅用于linux2.6以上內(nèi)核、可以大大提高nginx的性能
    use   epoll;
    #單個后臺worker process進(jìn)程的最大并發(fā)鏈接數(shù)
    worker_connections  1024;
    # multi_accept on; 
}

#設(shè)定http服務(wù)器、利用它的反向代理功能提供負(fù)載均衡支持
http {
     #設(shè)定mime類型、類型由mime.type文件定義
    include       mime.types;
    default_type  application/octet-stream;
    #設(shè)定日志格式
    access_log    logs/access.log;

    #sendfile 指令指定 nginx 是否調(diào)用 sendfile 函數(shù)(zero copy 方式)來輸出文件、對于普通應(yīng)用
    #必須設(shè)為 on、如果用來進(jìn)行下載等應(yīng)用磁盤IO重負(fù)載應(yīng)用、可設(shè)置為 off
    #以平衡磁盤與網(wǎng)絡(luò)I/O處理速度、降低系統(tǒng)的uptime
    sendfile        on;
    #tcp_nopush     on;

    #連接超時時間
    #keepalive_timeout  0;
    keepalive_timeout  65;
    tcp_nodelay        on;
    
    #開啟gzip壓縮
    gzip  on;
    gzip_disable "MSIE [1-6].(?!.*SV1)";

    #設(shè)定請求緩沖
    client_header_buffer_size    1k;
    large_client_header_buffers  4 4k;

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;

    #設(shè)定負(fù)載均衡的服務(wù)器列表
    upstream mysvr {
        #weigth參數(shù)表示權(quán)值,權(quán)值越高被分配到的幾率越大
        #本機上的Squid開啟3128端口
        server 192.168.8.1:3128 weight=5;
        server 192.168.8.2:80  weight=1;
        server 192.168.8.3:80  weight=6;
    }

    server {
        #偵聽80端口
        listen       80;
        #定義使用www.dwtedx.com dwtedx.com訪問
        server_name  dwtedx.com www.dwtedx.com;

        #設(shè)定本虛擬主機的訪問日志
        access_log  logs/www.xx.com.access.log  main;

        #默認(rèn)請求
        location / {
            root   /root/workspace;    #定義服務(wù)器的默認(rèn)網(wǎng)站根目錄位置
            index index.php index.html index.htm;    #定義首頁索引文件的名稱

            fastcgi_pass  dwtedx.com;
            fastcgi_param  SCRIPT_FILENAME  $document_root/$fastcgi_script_name; 
        }

        # 定義錯誤提示頁面
        error_page   500 502 503 504 /50x.html;  
            location = /50x.html {
            root   /root/workspace;
        }

        #靜態(tài)文件,nginx自己處理
        location ~ ^/(images|javascript|js|css|flash|media|static)/ {
            root /var/www/virtual/htdocs;
            #過期30天,靜態(tài)文件不怎么更新,過期可以設(shè)大一點,如果頻繁更新,則可以設(shè)置得小一點。
            expires 30d;
        }
        #PHP 腳本請求全部轉(zhuǎn)發(fā)到 FastCGI處理. 使用FastCGI默認(rèn)配置.
        location ~ .php$ {
            root /root/workspace;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME /home/www/www$fastcgi_script_name;
            include fastcgi_params;
        }
        #設(shè)定查看Nginx狀態(tài)的地址
        location /NginxStatus {
            stub_status            on;
            access_log              on;
            auth_basic              "NginxStatus";
            auth_basic_user_file  conf/htpasswd;
        }
        #禁止訪問 .htxxx 文件
        location ~ /.ht {
            deny all;
        }
    }
}


以上是一些基本的配置、使用OpenResty最大的好處就是負(fù)載均衡、這也是Nginx的特性、如果要使用負(fù)載均衡的話、可以修改配置http節(jié)點如下

#設(shè)定http服務(wù)器,利用它的反向代理功能提供負(fù)載均衡支持
http {
    #設(shè)定mime類型,類型由mime.type文件定義
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    #設(shè)定日志格式
    access_log    /root/workspace/access.log;

    #省略上文有的一些配置節(jié)點

    #設(shè)定負(fù)載均衡的服務(wù)器列表
    upstream mysvr {
        #weigth參數(shù)表示權(quán)值,權(quán)值越高被分配到的幾率越大
        server 192.168.8.1x:3128 weight=5;#本機上的Squid開啟3128端口
        server 192.168.8.2x:80  weight=1;
        server 192.168.8.3x:80  weight=6;
    }

    upstream mysvr2 {
        #weigth參數(shù)表示權(quán)值,權(quán)值越高被分配到的幾率越大

        server 192.168.8.x:80  weight=1;
        server 192.168.8.x:80  weight=6;
    }
   
}


另外、OpenResty同樣也繼承了Nginx的優(yōu)點、就是配置虛擬服務(wù)器、可以讓80端口同時處理多個網(wǎng)站、非常實用

server {
        listen       80;
        server_name  diapp.dwtedx.com;

        location / {
            #轉(zhuǎn)發(fā)Tomcat8080端口
            proxy_pass   http://127.0.0.1:8080;
        }
    }

    server {
        listen       80;
        server_name  app.dwtedx.com;

        location / {
            #到app目錄
            root   /root/workspace/app;
            index  index.html index.htm;
        }
        error_page  404              /404.html;
    }

    server {
        listen       80;
        server_name  income.dwtedx.com;

        location / {
            #到income目錄
            root   /root/workspace/income;
            index  index.html index.htm;
        }
        error_page  404              /404.html;
    }

    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
}



    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多