Skip to main content

How to deploy dist.zip VueJS Project on a cutomized Nginx image with SSL - Using a Dockerfile

let's assume you have already activated your certificate SSL so in other words, you have got the cert-chain.crt and the server.key or whatever name you've given to it, and let's assume you've got an nginx.conf  file working already,  let's create a folder in which you're going to create your Docker Image
and copy in there the next files:

cert-chain.crt
server.key
dist.zip
nginx.conf

this is the nginx.conf on centos

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
# with this, we are redirecting traffic from 80 to https 443      listen 80 default_server;

      server_name sslbackendtest.xyz;
      return 301  https://sslbackendtest.xyz$request_uri;
    }

    server {

      listen 443 ssl;
   
      ssl_certificate /etc/ssl/cert-chain.crt;
      ssl_certificate_key /etc/ssl/server.key;


      server_name  https://sslbackendtest.xyz;
      access_log /var/log/nginx/nginx.vhost.access.log;
      error_log /var/log/nginx/nginx.vhost.error.log;
      root    /var/www/html/dist;
        location / {
        root /var/www/html/dist;
        try_files $uri /index.html;
      }

    }

}



let's create a file called Dockerfile, and inside of it let's paste 

FROM nginx

RUN apt-get update && apt-get install unzip
COPY nginx.conf /etc/nginx/
COPY cert-chain.crt /etc/ssl/
COPY server.key /etc/ssl/
COPY dist.zip /var/www/html/
WORKDIR /var/www/html/
RUN unzip /var/www/html/dist.zip
RUN chown -R nginx:nginx /var/www/html/dist
now let's create it with the command docker build -t nginx1 .
I gave it the name nginx1, give it the name as you want

now let's open the port 443 in the firewall with 
firewall-cmd --zone="public" --add-port=443/tcp --permanent

to run it 

docker run -p 443:443 --name nginxcontainer1 nginx1

Getting to the shell container:

If you need now to get to the shell, run this
docker exec -it --user root nginxcontainer1 bash

We have been able to deploy the Nginx app building the image and running it into a container,
now let's run it in the background or (Detached mode)


docker run -d --rm -p 443:443 --name nginxcontainer1 nginx1

-d = it means detached mode
-rm = it means if the container is running, it removes it before starting it again
-p = it is the port from the host forwarded to the container port
--name = it is the name of the container, in this case, nginxcontainer1 

if you want to know if the container is running, just run docker container ps -a or docker container ls



Comments

Popular posts from this blog

How to deploy a VueJS App using Nginx on Ubuntu

There are thousands of blogs and websites out there explaining how to do a hello world and how to start with VueJS, but in this little post, I’m just going to be explaining how to do deploy a VueJs app after you have run the command through the CLI npm run build . So when you run the command npm run build a dist folder is created and that folder’s got the essential .js files to run our app, when we want to run our app on an Nginx server by default the vue-router is not going to work well so that Nginx does not come ready to work by default with a VueJs app This is basically for a Linux Ubuntu distribution if you’ve got any other Linux distribution just pay attention where is going to be set the www/html folder and the Nginx settings so that this is useful for any Linux distribution  Install and configure nginx sudo apt install nginx Double check to make sure the nginx service is running with command service nginx status, then open your browser and enter ...

Nginx reverse proxy for ReactJS, Vuejs,Laravel and Django with or without Docker

Nginx is an important piece on the working chain apps so that it works as bridge between the end user and the application servers, to do that we will be using nginx as a reverse proxy to know more in deep about nginx reverse proxy go to https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/ let's suppose you have a domain name called yourdomainame.com Nginx - ReactJS/Vuejs each time you need to create a new domain name, set it on the path /etc/nginx/conf.d/ create a file with vim or nano or whatever you want, and give it the domain name .conf and set the settings on it, this is really useful when you start handling several domain names under the same server vim /etc/nginx/conf.d/ yourdomainame.com.conf server {         server_name   yourdomainame.com wwww.yourdomainame.com;         # Load configuration files for the default server block.         include /etc/nginx/default.d/ *.conf ;   ...

Uploading and Deleting Files with Amazon S3 and SpringBoot

Today I am going to be sharing about how to upload and delete files at AmazonS3 with SpringBoot , Amazon Simple Storage Service (S3)  is an object storage platform which helps you to store the files in form of objects, it allows us to store and retrieve any amount of data from anywhere.  Each file is stored in Amazon S3 (as an object) and is represented using a key. we are going to be using AWS Java SDK which supports various APIs related to Amazon S3 service for working with files stored in S3 bucket. so after going to  https://start.spring.io/  and create a new SpringBoot project with the Artifact as  AmazonS3  or as you prefer, open your pom.xml and let's add this dependency. AWS Java SDK supports several  APIs related to Amazon S3 service for working with files stored in S3 bucket.  <!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk --> < dependency >     < groupId >...