Nginx反向代理配置

 

#運行用戶
#user somebody;
 
#啓動進程,通常設置成和cpu的數量相等
worker_processes  1;
 
#全局錯誤日誌
error_log  C:/Users/wangcw/Desktop/nginx-1.13.12/logs/error.log;
error_log  C:/Users/wangcw/Desktop/nginx-1.13.12/logs/notice.log  notice;
error_log  C:/Users/wangcw/Desktop/nginx-1.13.12/logs/info.log  info;
 
#PID文件,記錄當前啓動的nginx的進程ID
pid        C:/Users/wangcw/Desktop/nginx-1.13.12/logs/nginx.pid;
 
#工作模式及連接數上限
events {
    worker_connections 1024;    #單個後臺worker process進程的最大併發鏈接數
}
 
 
http {
     #設定mime類型,類型由mime.type文件定義
    include       C:/Users/wangcw/Desktop/nginx-1.13.12/conf/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    C:/Users/wangcw/Desktop/nginx-1.13.12/logs/access.log main;
    rewrite_log     on;
 
	#設置訪問的web應用列表
    upstream product_server{
        server www.aabbccdd.com:18080;
    }
    upstream admin_server{
        server www.aabbccdd.com:28080;
    }
    upstream finance_server{
        server www.aabbccdd.com:38080;
    }
 
   #HTTP服務器
   server {
        #監聽80端口,80端口是知名端口號,用於HTTP協議
        listen       80;
        
        #定義使用www.xx.com訪問
        server_name  www.aabbccdd.com;
        
        #首頁
        index index.jsp
        
        #指向webapp的目錄
        root C:/XMCARES_X/WorkSpace/nginx/src/main/webapp;
        
        #編碼格式
        charset utf-8;
        
        #代理配置參數
        proxy_connect_timeout 180;
        proxy_send_timeout 180;
        proxy_read_timeout 180;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarder-For $remote_addr;
        
       
 
        #默認指向product的server
        location / {
            proxy_pass http://product_server;
        }
 
		#使用location對不同請求做相應處理
        location /product/{
            proxy_pass http://product_server;
        }
 
        location /admin/ {
            proxy_pass http://admin_server;
        }
        
        location /finance/ {
            proxy_pass http://finance_server;
        }
    }
}

 

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