How to configure Nginx’s reverse proxy to proxy multiple ports to different directories on the same port?
I have applications A, B and C, which run on ports 8001, 8002 and 8003 respectively.
The server does not have a domain name configured, so the access address isip:8001、ip:8002Andip:8003.
Now I want to use Nginx to implement, only open an 80 port, and then access different services through different directories.
I expect the access address to becomeip:80/a、ip:80/bAndip:80/c. And all resource requests under this application are based on this path.
such asip:80/aYou can jump toip:80/a/loginInstead ofip:80/login, pay attention to the directory.
My /etc/nginx/conf.d/default.conf is as follows:
server {
listen 80;
server_name localhost;
location /a {
proxy_pass http://127.0.0.1:8001/;
}
location /b {
proxy_pass http://127.0.0.1:8002/;
}
location /c {
proxy_pass http://127.0.0.1:8003/;
}
}
According to my above configuration, enterip:80/aI did see a successful agentip:8001The application, only look at the home page, everything is normal.
But a jumpip:80/a/user/**Such a multi-level directory fails and becomesip:80/user/**.
I have also tried to use official documents, regular configuration of location or rewrite, but I cannot achieve the desired effect.
Thank you for your advice.
I’ve tried, no, unless there is a domain name.