I am deploying a docker container, which includes my webapp (app 1) to a vm. I have another docker container (app 2) on the vm that is running on port 8080
. I would like to proxy all url requests from app 1
that start with /api
to app 2
.
This is my DOCKER file:
FROM nginx:1.17.0
MAINTAINER **** [**@**.com](mailto:**@**.com)
COPY nginx.default /etc/nginx/sites-enabled/default
ADD dist/ /usr/share/nginx/html/
These are my webpack dev server settings
devServer: {
contentBase: outDir,
// serve index.html for all 404 (required for push-state)
historyApiFallback: true,
proxy: {
'/api': {
target: 'http://aapp-name:8080',
pathRewrite: { '^/api': '' },
logLevel: 'debug'
}
}
}
I have added the following to nginx.default
, but it doesn't seem to be working.
location /api {
proxy_pass http://app-name:8080;
}
If you want to access container by name, you should place them in the same docker network.
docker network create <network_name>
docker run --network <network_name> --name app2 -d -p 8080:8080 image
docker run --network <network_name> --name app1 -d image
http://app2:8080
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.