windows nginx根据请求地址配置反响代理(同一个ng端口)

2024-01-25 10:43:37 浏览数 (1)

代码语言:javascript复制
#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;
    sendfile        on;
    keepalive_timeout  65;

    upstream driver-interface{
	server ip1:8081 max_fails=0;
        #server ip2:8082 max_fails=0;
    }

    upstream driver-admin{
	#server 218.66.19.173:8081 max_fails=0;
        server 192.168.3.21:8082 max_fails=0;
    }
    

    server {
        listen       80;
        server_name  localhost;

        location /drive/mobile/{    //这里控制接口(mobile)代理跳转
            root   html;
            proxy_redirect    off;
            proxy_set_header  Host $host:80;
            proxy_set_header  X-Real-IP  $remote_addr;
            proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
            index  index.html index.htm;
            proxy_pass  http://driver-interface;
       	    proxy_redirect  default;        
	 }
        location ~ .*/(admin|js|css|img|images) {   //这里控制管理后台(admin)代理跳转,由于后台有样式,js以及图片,前缀不包含admin。所以也需要在这里配置
            root   html;
            index  index.html index.htm;
            //一下是将请求的域名重新转发到页面(分页中,或直接获取请求域名的需要,如果不配置激昂读取到http://driver-interface)
            proxy_redirect    off;
            proxy_set_header  Host $host:80;
            proxy_set_header  X-Real-IP  $remote_addr;
            proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass  http://driver-admin;
       	    proxy_redirect  default;        
	 }

        location / {
            root   html;
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    }

}

0 人点赞