I used Angular-CLI to create a test app and serve it using Nginx. Got either a 404 or a 403. I guess it is a problem with my Nginx config but just to be additionally sure, I have provided all the steps that I performed to get to this point.
These are the steps I followed:
- Installed angular-cli: - npm install -g @angular/cli
- Started a new project: - ng new test-angular
- Checked using - ng-serveand it works.
- Built the project to be served using nginx: - ng build. Creates a- distfolder within the project directory.
- Changed my nginx config: - events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; server { listen 80 default_server; root /home/mellkor/test-angular/dist; index index.html index.htm; server_name localhost; location / { try_files $uri $uri/ =404; } } }
nginx -s reload successful. On hitting localhost, I get a 404 Not Found.
Based on some suggestions, changing to try_files $uri /index.html gives me a 403 Forbidden.
Another question: since ng init doesn't seem to work anymore, how can I initialize an existing angular2 application and build it to production using angular-cli?
Yes I did refer this closed topic, but there is no solution there so far.
Additional Information:
@angular/cli: 1.0.0-rc.0
node: 7.5.0
os: linux x64
@angular/common: 2.4.8
@angular/compiler: 2.4.8
@angular/core: 2.4.8
@angular/forms: 2.4.8
@angular/http: 2.4.8
@angular/platform-browser: 2.4.8
@angular/platform-browser-dynamic: 2.4.8
@angular/router: 3.4.8
@angular/cli: 1.0.0-rc.0
@angular/compiler-cli: 2.4.8
 
    