Home > Software design >  Deploy Reactapp using Docker & SSL
Deploy Reactapp using Docker & SSL

Time:11-09

Dockerfile

Docker run command : docker run -itd -p 8080:80 prod

FROM node:16-alpine as builder
WORKDIR /app
COPY package.json ./
COPY package-lock.json ./
COPY . /app/

RUN npm install --silent
RUN npm install [email protected] -g --silent
RUN npm run build
# production environment
FROM nginx:1.21.1-alpine
COPY --from=builder /app/build /usr/share/nginx/html

EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

defalut.conf file

server {

listen 443 ssl default_server;
listen [::]:443 ssl default_server;

ssl_certificate /etc/nginx/sites-available/cert.crt;
ssl_certificate_key /etc/nginx/sites-available/ssl.key;

server_name ipaddress;

location / {
proxy_pass http://localhost:8080;
try_files $uri /index.html;
}

I am unable to see my index.html file running on my ip Address in https. its working fine with http://ipaddress:8080. Above is the Configuration File of DockerFile & default.conf file. nothing is showing in server logs.

I want to know that is the above configuration is correct or esle how to deploy react-app using Docker & SSL & Nginx

CodePudding user response:

By Looking at your comments it looks like your port configuration is not correct, in NginX port listening is set to listen on port 443, but your docker port configuration is using port 80 as host port. Assuming Node server is listening at port 8080, docker run should be like this

$ docker run -itd -p 443:443 prod

And try https://ipaddress , based on certificate setting you should see either warning in browser (if certificate is not trusted fully, you might need to add it as an exception), or see proper contents.

  • Related