nginx搭建反向代理和負載均衡

1、找到nginx的配置文件

/usr/local/nginx/conf/nginx.conf


2、訪問靜態資源最簡單的配置(訪問路徑:http://localhost:81)

# 靜態http服務器
    server {
	# 監聽80端口
        listen       81;
	# 域名 這裏是本地訪問
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
	
	# 需要映射的地址(這裏以/開頭)
        location / {
	    # 靜態資源的根目錄
            root   html81;
	    # index頁面
            index  index.html index.htm;
        }
    }


3、反向代理服務器(通俗來說,就是客戶端訪問某個域名,通過DNS解析出一個ip地址,然後在這個ip的服務器上配置了一個nginx作爲中間服務器,用來負責轉發tomcat等服務器的請求及把響應結果返回給客戶端)
用圖直觀的說明:



4、作爲反向代理服務器的配置

upstream search {
	server 10.9.96.75:8080;
    }
    server {
	# 監聽80端口
        listen       80;
	# 域名
        server_name  www.taotao.search.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
	    # 代理的地址
            proxy_pass   http://search;
            index  index.html index.htm;
        }
    }



5、作爲負載均衡服務器的配置 (只需要設置weight值來)

upstream item {
	server 10.9.96.75:8081 weight=1;
	server 10.9.96.75:8082 weight=3;
    }



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