I have an angular app, my-app, which I build locally with ng build --prod and serve with Nginx dockerized, the Dockerfile is:
FROM nginx:alpine
COPY /dist/my-app /usr/share/nginx/html
EXPOSE 80
As long as I launch a container based on an image build with this Dockerfile, it works.
Though, I need to put another Nginx acting as a reverse proxy before this one, I want to redirect the traffic with a route like /my-app to the internal Nginx serving Angular, like so:
http://DOMAIN/my-app ---> Reverse Proxy ---> Nginx+Angular
I'll use Docker Compose for local dev. My docker-compose.yml is very simple:
version: '3'
services:
nginx:
container_name: my-nginx
build: ./nginx
ports:
- "80:80"
my-app:
container_name: my-app
build: ./my-app
For the Angular app, I redefine "baseHref": "./my-app/" in my angular.json file, I build again and I configure the reverse proxy as follows:
events {}
http {
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www;
index index.html;
location / {
index index.html;
}
location /my-app {
rewrite /my-app/(.*) /$1 break;
proxy_pass http://my-app:80;
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
proxy_set_header Host $host;
}
}
}
Here, the index.html in the location / directive is a custom one, not the Angular app's one. Thus, I expect my reverse proxy to serve the index.html when visiting the route /, which it does, but I get a 400 Bad Request error when I try to visit /my-app/.
Does someone have a solution for this? What am I getting wrong? Thanks!