开发者

PathStrategy with Angular and Nginx not working

开发者 https://www.devze.com 2022-12-07 19:38 出处:网络
I have an angular app that is built inside the dist folder as dist/register. I am using docker and NGINX to deploy the application, now I have a docker file that looks like this.

I have an angular app that is built inside the dist folder as dist/register. I am using docker and NGINX to deploy the application, now I have a docker file that looks like this.

# Stage 1

FROM node:18-alpine as build-step

RUN mkdir -p /app-ui

WORKDIR /app-ui

COPY package.*json /app-ui

RUN npm install

COPY . /app-ui


RUN npm run build


# Stage 2

FROM nginx:alpine

#!/bin/sh

COPY ./.nginx/nginx.conf /etc/nginx/nginx.conf

## Remove default nginx index page
RUN rm -rf /usr/share/nginx/html/*

# Copy from the stahg 1
COPY --from=build-step /app-ui/dist /usr/share/nginx/html

EXPOSE 4200 80

ENTRYPOINT ["ngi开发者_高级运维nx", "-g", "daemon off;"]

and my nginx conf looks like this.

worker_processes 4;

events { worker_connections 1024; }

http {
    server {
        listen 80;
        root  /usr/share/nginx/html;
        include /etc/nginx/mime.types;

        location /appui {
            try_files $uri $uri/ /register/index.html;
        }
    }
}

Now, when I build the docker image, my subroutes are not working, i.e the localhost/ URL works and servers the index page of my app but as soon as I go to something like localhost/users, it fails and gives me 404.

Now, upon research I found that I can also use HashLocationStrategy and it worked as well but it changes the URL and appends a #, is there a way to make pathStrategy work?

Any help is appreciated.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号