5
回答
咨询nginx反向代理问题
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   

如下图所示,请问nginx.conf文件怎么配置

举报
CAIR
发帖于5年前 5回/422阅
共有5个答案 最后回答: 5年前
#user  nobody;
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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    gzip  on;

	proxy_connect_timeout 2s;
	
	
	upstream tomcat_pool {
		server x.x.x.84:8080;
		server x.x.x.85:8081;
	}
	
	upstream report_pool {
		server	x.x.x.85:8080;
		#server 127.0.0.1:8081 down;
	}
	
    server {
        listen       80;
        server_name  x.x.x.x;
		
		
        #charset koi8-r;

        #access_log  logs/host.access.log  main;
		
		proxy_buffer_size	16k;
		proxy_buffers	4 16k;

        location /xxx/ {
			proxy_pass http://tomcat_pool/itsm/;
			proxy_set_header Host $host;
			proxy_set_header X-Real-IP $remote_addr;
			proxy_set_header REMOTE-HOST $remote_addr;
			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;   
		}
		
		location  /xxx2/ {
			proxy_pass http://report_pool/report/;
			proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header REMOTE-HOST $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		}
   }

}
参考一下这个配置,手册上写的很详细,建议参考手册

引用来自“恺哥”的答案

#user  nobody;
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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    gzip  on;

	proxy_connect_timeout 2s;
	
	
	upstream tomcat_pool {
		server x.x.x.84:8080;
		server x.x.x.85:8081;
	}
	
	upstream report_pool {
		server	x.x.x.85:8080;
		#server 127.0.0.1:8081 down;
	}
	
    server {
        listen       80;
        server_name  x.x.x.x;
		
		
        #charset koi8-r;

        #access_log  logs/host.access.log  main;
		
		proxy_buffer_size	16k;
		proxy_buffers	4 16k;

        location /xxx/ {
			proxy_pass http://tomcat_pool/itsm/;
			proxy_set_header Host $host;
			proxy_set_header X-Real-IP $remote_addr;
			proxy_set_header REMOTE-HOST $remote_addr;
			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;   
		}
		
		location  /xxx2/ {
			proxy_pass http://report_pool/report/;
			proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header REMOTE-HOST $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		}
   }

}
参考一下这个配置,手册上写的很详细,建议参考手册
主要就是proxy_pass指向后端就可以
顶部