隨手記--nginx

發現自己以前做過負載均衡,但是沒記錄下來....隨便寫寫,以便以後再學習有印象。

有不對的地方歡迎指出~~

nginx是代理服務器 可高併發
 目前就試驗了這兩個功能,代理服務器和負載均衡,舉例子; 
1.   nginx所在服務器爲10.1.1.1   你設置它監聽8080端口 代理10.1.1.2:8888   用戶訪問你的10.1.1.1:8080  頁面會顯示10.1.1.2:8888的內容  
2.負載均衡  如果你的客戶端 用戶量很大  這樣一臺服務器承受不了   你就在兩臺服務器10.1.1.11  10.112.1.12 上安裝客戶端   設置nginx監聽端口8081  隨機訪問這兩臺服務器   用戶訪問10.1.1.1:8081   就會隨機(隨機性可設置)訪問這兩臺服務器


可查看這些文章學習,感覺寫的很棒~:

http://blog.csdn.net/u014749862/article/details/50522276

http://blog.csdn.net/shimiso/article/details/8690897

http://www.jb51.net/article/47755.htm

http://tengine.taobao.org/book/module_development.html

http://www.cnblogs.com/jingmoxukong/p/5945200.html

http://outofmemory.cn/code-snippet/3074/nginx-load-junheng-configuration-jizhong-strategy

http://linux.it.net.cn/e/server/nginx/2015/0621/15898.html

** http://jsczxy2.iteye.com/blog/1423404

安裝就不說了。

查看是否安裝nginx:

nginx -v 

啓動nginx:

nginx -c /etc/nginx/nginx.conf
(直接輸入服務器網址出現nginx頁面就安裝成功了)


nginx -s reload  :修改配置後重新加載生效
nginx -s reopen  :重新打開日誌文件
nginx -t -c /path/to/nginx.conf 測試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 {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
server {
                listen 8888;  //監聽端口

                server_name 10.1.X.X;   //監聽服務器

                location  / {

                        proxy_pass http://blance; //對應下面upstream配置的名爲blance(隨意起名字)
                 }

        }
        upstream blance{  //配置需負載均衡的服務器

            #    server localhost:3280 weight=5;  
                 server   IP1:端口;
                 server   IP2:端口;
             #   server localhost:3380 weight=5;

        }   

server {


                listen 8080;  //配置另一個代理

                server_name 10.1.12.140;
           location / {
                proxy_pass http://IP:8088/;  //有一點沒搞懂,整個地址應該是http://IP:8088/Jenkins ,但是配置後會訪問失敗,把jenkins去掉卻訪問了正確的Jenkins頁面
        }


}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章