there is no operation and maintenance in our company for the time being. I have been helping to build and configure nginx. I received a demand today. I think I can"t figure it out after reading it on the Internet, right? I would like to ask you:
our company has two servers, one a.company.com, one b.company.com
a.company.com/ is the static resource for a project
a.company.com/api is the dynamic interface for a project
b.company.com/ is the static resource for project b (internal network project, external network cannot be accessed, but want to demonstrate to customers, so there is this problem)
now you want to reverse proxy b.company.com/admin with a.company.com/admin, which is only the admin directory of the proxy b.company.com, and will not affect the functionality of the original a.company.com/ and a.company.com/api. I"ve tried several configurations and feel that I just can"t do this as a proxy for another server"s single directory. Here is my complete nginx.conf:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
sendfile on;
default_type application/octet-stream;
keepalive_timeout 65;
client_max_body_size 10m;
fastcgi_intercept_errors on;
proxy_headers_hash_max_size 51200;
proxy_headers_hash_bucket_size 6400;
server {
root /usr/share/nginx/html;
index index.html;
listen 80;
server_name a.company.com;
location / {
index index.html;
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept";
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
}
location ^~ /api/ {
proxy_pass http://localhost:8888;
proxy_buffers 4 512k;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-real-ip $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_buffer_size 512k;
proxy_http_version 1.1;
proxy_read_timeout 600s;
proxy_send_timeout 600s;
proxy_connect_timeout 600s;
proxy_busy_buffers_size 512k;
proxy_temp_file_write_size 512k;
}
location ^~ /admin/ {
proxy_pass http://b.company.com/admin;
proxy_set_header Host $host;
proxy_set_header X-real-ip $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
}
}
}
I would like to ask whether this is feasible? What should I do if it"s feasible?