I am trying to deploy an Angular 2 that uses the router capabilities of the framework but I am having some issues serving it with nginx inside a docker container.
An angular app built by the angular-cli, has a file structure like this:
./dist
├── 08c42df75dd2c636f46f3c564b3ddaa5.ttf
├── 8eab7754b320d3562a2deff1ca81bb6f.woff2
├── assets
│ ├── fonts
│ │ ├── Avenir_Next_New_Regular.otf
│ │ ├── Avenir_Next_New_Regular.ttf
│ │ └── material.woff2
│ └── img
│ ├── angular-2.svg
├── index.html
├── inline.js
├── main.dc3f8a76e21296ab1f32.bundle.js
├── main.dc3f8a76e21296ab1f32.bundle.js.gz
├── styles.771fbb659c3d6c4edd71.bundle.js
└── styles.771fbb659c3d6c4edd71.bundle.js.gz
I am trying to deploy using the below dockerfile
FROM nginx:1.10-alpine
COPY dist/ /var/www
COPY ng2.conf /etc/nginx/conf.d/default.conf
CMD 'nginx'
The tricky part is how to setup the default.conf file below:
server {
listen 80;
root /var/www/;
// The question is how do I set this location block
// making sure both angular and the local files are happy?
location / {
try_files $uri /index.html;
}
}
It all works except the angular routes. Meaning / works but /resume get redirected to /
const appRoutes: Routes = [
{
path: '',
component: DevComponent
},
{
path: 'resume',
component: ResumeComponent
}
];
export const router: ModuleWithProviders = RouterModule.forRoot(appRoutes);
/resumerequest shouldn't hit nginx. It should be handled at the client side by angular. Your nginx here should only be used to handle the initial download of your angular app. So I'd focus on your angular settings. Can you post more here.