我想部署一個使用框架的路由器功能的Angular 2,但我有一些問題在docker容器內爲nginx服務。使用Nginx在Docker容器內部署帶有路由器的Angular2
由角CLI構建的角度應用程序,有一個文件的結構是這樣的:
./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
我嘗試使用下面的dockerfile
FROM nginx:1.10-alpine
COPY dist/ /var/www
COPY ng2.conf /etc/nginx/conf.d/default.conf
CMD 'nginx'
棘手的部分部署是如何設置下面的default.conf
文件:
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;
}
}
這一切除了角路徑的作品。意義/作品,但/恢復重定向到/
const appRoutes: Routes = [
{
path: '',
component: DevComponent
},
{
path: 'resume',
component: ResumeComponent
}
];
export const router: ModuleWithProviders = RouterModule.forRoot(appRoutes);
'/ resume'請求不應該打到nginx。應該在客戶端處理角度。你的nginx在這裏只能用來處理你的角度應用程序的初始下載。所以我會專注於你的角度設置。你能在這裏發佈更多嗎? – Alkaline
@Alkaline在本地主機上工作,因爲它應該是。 – CESCO