我司暫時(shí)沒(méi)有運(yùn)維,一直都是我在幫忙搭建和配置nginx,今天接到一個(gè)需求,我上網(wǎng)看一圈之后覺(jué)得弄不出來(lái)的吧?想請(qǐng)教一下各位:我司有兩臺(tái)服務(wù)器,一個(gè)a.company.com,一個(gè)b.company.coma.company.com/是放a項(xiàng)目的靜態(tài)資源a.company.com/api是訪問(wèn)a項(xiàng)目動(dòng)態(tài)接口b.company.com/是放b項(xiàng)目的靜態(tài)資源(內(nèi)網(wǎng)項(xiàng)目,外網(wǎng)無(wú)法訪問(wèn),但是想演示給客戶看,所以有了這個(gè)問(wèn)題)現(xiàn)在想用a.company.com/admin反向代理b.company.com/admin,僅僅是代理b.company.com的admin目錄,不會(huì)影響原來(lái)a.company.com/和a.company.com/api的功能。我試過(guò)好幾個(gè)配置,感覺(jué)就是不能這樣做另一個(gè)服務(wù)器單個(gè)目錄的代理。下面是我的完整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;}}}我想問(wèn)這是可行的嗎?如果可行要怎么弄呢?
Nginx 可以代理另一個(gè)網(wǎng)站的目錄嗎?
尚方寶劍之說(shuō)
2019-05-07 10:13:49