我司暂时没有运维,一直都是我在帮忙搭建和配置nginx,今天接到一个需求,我上网看一圈之后觉得弄不出来的吧?想请教一下各位:我司有两台服务器,一个a.company.com,一个b.company.coma.company.com/是放a项目的静态资源a.company.com/api是访问a项目动态接口b.company.com/是放b项目的静态资源(内网项目,外网无法访问,但是想演示给客户看,所以有了这个问题)现在想用a.company.com/admin反向代理b.company.com/admin,仅仅是代理b.company.com的admin目录,不会影响原来a.company.com/和a.company.com/api的功能。我试过好几个配置,感觉就是不能这样做另一个服务器单个目录的代理。下面是我的完整nginx.conf:worker_processes1;events{worker_connections1024;}http{includemime.types;sendfileon;default_typeapplication/octet-stream;keepalive_timeout65;client_max_body_size10m;fastcgi_intercept_errorson;proxy_headers_hash_max_size51200;proxy_headers_hash_bucket_size6400;server{root/usr/share/nginx/html;indexindex.html;listen80;server_namea.company.com;location/{indexindex.html;add_headerAccess-Control-Allow-Origin*;add_headerAccess-Control-Allow-Headers"Origin,X-Requested-With,Content-Type,Accept";add_headerAccess-Control-Allow-Methods"GET,POST,OPTIONS";}location^~/api/{proxy_passhttp://localhost:8888;proxy_buffers4512k;proxy_redirectoff;proxy_set_headerHost$host;proxy_set_headerUpgrade$http_upgrade;proxy_set_headerConnection"upgrade";proxy_set_headerX-real-ip$remote_addr;proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;proxy_buffer_size512k;proxy_http_version1.1;proxy_read_timeout600s;proxy_send_timeout600s;proxy_connect_timeout600s;proxy_busy_buffers_size512k;proxy_temp_file_write_size512k;}location^~/admin/{proxy_passhttp://b.company.com/admin;proxy_set_headerHost$host;proxy_set_headerX-real-ip$remote_addr;proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;proxy_set_headerREMOTE-HOST$remote_addr;}}}我想问这是可行的吗?如果可行要怎么弄呢?
添加回答
举报
0/150
提交
取消