详解nginx 代理多个服务器(多个server方式)

 其中主要的是有两个server,每个server对应的被代理的服务器的不同。从而实现了nginx代理多个服务器的目的。

user  root;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       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;
    error_log  /var/log/nginx/error.log;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
	#listen port
        listen		8888;
	#server ip
	server_name	127.0.0.1;    
    
    #client_max_body_size
    client_max_body_size 10M;

		location / {
			root /home/baoxin/web/na;
			try_files $uri $uri/ @router;
			index index.html;
		}

		location ^~/admin/ {
			proxy_pass   http://127.0.0.1:9999/admin/;
		}
    
		location ^~/auth/ {
			proxy_pass   http://127.0.0.1:9999/auth/;
		}
    
 		 location /group1/M00 {
			alias /home/data/fastdfs/storage/data/data;
		}
    }

	#knowledgeBase
    server {
	#listen port
        listen		1111;
	#server ip
	server_name	127.0.0.1;    
    
    #client_max_body_size
    client_max_body_size 10M;

		location / {
			root /home/baosight/knowledgeBase/web/na;
			try_files $uri $uri/ @router;
			index index.html;
		}

		location ^~/admin/ {
			proxy_pass   http://127.0.0.1:9998/admin/;
		}
    
		location ^~/auth/ {
			proxy_pass   http://127.0.0.1:9998/auth/;
		}
    
 		 location /group1/M00 {
			alias /home/data/fastdfs/storage/data/data;
		}
    }

}

 

你可能感兴趣的:(详解nginx 代理多个服务器(多个server方式))