Deploy and config NGINX on Angular 7 + Nginx Docker
- Create and run docker image
- docker run --name app-nginx -p 9595:80 -v /media/storage/angular7nginx-app/:/usr/share/nginx/html:ro -d nginx
- Go to docker image
- docker exec -ti app-nginx /bin/bash
- vim /etc/nginx/nginx.conf
- Add these line of code inside the http
- Restart docker container
- Check docker logs
- docker logs app-nginx
- app-nginx is application name
server {
listen 80;
listen [::]:80;
server_name http://ip;
root /usr/share/nginx/html;
index index.html index.htm;
location / {
try_files $uri $uri/ /index.html;
# This will allow you to refresh page in your angular app. Which will not give error 404.
}
}
usefull commands on docker:
- docker commit app-nginx nginx:latest --> create a new docker with latest tag
- docker logs app-nginx -f --> tail docker log with -f option
- docker ps -a --> see running dockers in details
- docker rm app-nginx --> remove app-nginx docker image