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

详解nginx 代理多个服务器(多个server方式)
强烈推介IDEA2020.2破解激活,IntelliJ IDEA 注册码,2020.2 IDEA 激活码

 其中主要的是有两个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;
		}
    }

}

 

本文来源huayang183,由架构君转载发布,观点不代表Java架构师必看的立场,转载请标明来源出处:https://javajgs.com/archives/18775

发表评论