Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular app + NGINX + Docker

I have problem with serving Angular app using nginx on docker. Problem is only when I want to turn on SSL on site. I'm using Bamboo for deployment.

Here is my Dockerfile:

FROM node:8.6 as node
WORKDIR /app
COPY package.json /app/
COPY ssl/certificate.crt /app/
COPY ssl/ /app/ssl

RUN npm install -g @angular/cli --unsafe
RUN npm install

COPY ./ /app/
RUN ng build --prod --aot=false --env=prod

FROM nginx

RUN mkdir -p /ssl
COPY --from=node /app/ssl/ /ssl/
ADD ssl/certificate.crt /etc/nginx/certs/
ADD ssl/private.key /etc/nginx/certs/
RUN ls /etc/nginx/certs/

COPY --from=node /app/dist/ /usr/share/nginx/html

RUN ls /usr/share/nginx/html

Script to run:

docker build -t test-app .
docker run --name test-app-cont -v /etc/nginx/certs:/etc/nginx/certs -d -p 3010:443 test-app

Deployment runs successfully, but there is no app on server served.

Please have a look at this screen: There is listed what is in /certs and /html directories. Everything seems to be good.

enter image description here

If I remove these lines dedicated to SSL, everything works fine, and on server I can see my app, but only through http.

The certificates are valid, I checked.

What am I doing wrong?

like image 758
Maciej Wojcik Avatar asked Oct 17 '22 21:10

Maciej Wojcik


1 Answers

To enable the SSL you need to configure the Nginx for it. As far as I see in your code, you are still using the default Nginx config without any modifications. Here is an example on how to enable SSL on Nginx. The main components are:

server {

    listen 443;
    server_name jenkins.domain.com;

    ssl_certificate           /etc/nginx/cert.crt;
    ssl_certificate_key       /etc/nginx/cert.key;

    ssl on;
    ssl_session_cache  builtin:1000  shared:SSL:10m;
    ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
    ssl_prefer_server_ciphers on;

Also I see that you mount a volume (-v /etc/nginx/certs:/etc/nginx/certs) in the docker run command, this means that the /etc/nginx/certs in the container will be same as the host and so make sure you have the correct certificates on the host machine!

like image 173
KarateKid Avatar answered Oct 21 '22 09:10

KarateKid