nginx with docker for frontend local development
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
root /usr/share/nginx/app/public;
location / {
# root /usr/share/nginx/app/public; # this is your frontend code after build , change the if the starting point isn't the public folder
try_files $uri $uri/ /index.html =404;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html; ## replace those if you have a custom page with each error ,and what to use it .
location = /50x.html {
root /usr/share/nginx/html;
}
location /api { ## your backend needs to have /api in the url for the nginx do redirect the api calls to the dev enviroment
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Authorization $http_authorization;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass https://dev.domain.com; ## ${NGINX_PROXY_PASS_URL_DEV} //TODO will be used to prevent editing the file .
}
}
$ sudo docker run --name frontend -v ~/path/to/app:/usr/share/nginx/app:ro -v ~/path/to/dev.conf:/etc/nginx/conf.d/default.conf:ro -p 8080:80 -d nginx:stable-alpine
docker-machine ssh default -L 8080:localhost:8080