Nginx反向代理配置

Nginx反向代理配置

server {	
	listen       8000;
	server_name  localhost;
	autoindex on;
	add_header Access-Control-Allow-Origin *;
	add_header Access-Control-Allow-Credentials true;  
	add_header Access-Control-Allow-Headers X-Requested-With;
	add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
	rewrite ^/([^\/]+)/app.min.(css|js)$  /$1/app.$2 last;

	location / {
		proxy_pass http://127.0.0.1:9528;
	}
			
	location /edu-admin-web/ {
		proxy_pass http://127.0.0.1:8080;
	}

	charset utf-8;
	access_log  logs/host.access.log  main;				
 }

 在Nginx中location配置proxy_pass时,当在后面的url加上了/,相当于是绝对根路径,则nginx不会把location中匹配的路径部分代理走;如果没有/,则会把匹配的路径部分也给代理走。 

下面四种情况分别用http://localhost:8000/edu-admin-web/rest/teacher/list?pageNum=1&numPerPage=20 进行访问。

  1. location /edu-admin-web/ {
                proxy_pass http://127.0.0.1:8080/;
    };  代理到: http://127.0.0.1:8080/rest/teacher/list?pageNum=1&numPerPage=20;
  2. location /edu-admin-web/ {
                proxy_pass http://127.0.0.1:8080;
    };  代理到: http://127.0.0.1:8080/edu-admin-web/rest/teacher/list?pageNum=1&numPerPage=20;

 

你可能感兴趣的:(Nginx)