- A simple Spring Boot application running behind NGINX and inside docker containers
- Docker CE
- Docker
- Java
- Spring Boot
- NGINX
- Maven
- Run command
docker-compose up
- Access to http://localhost/
A simple Spring Boot web application running behind NGINX and inside Docker containers
Home Page: https://hellokoding.com/docker-compose-with-spring-boot-nginx/
License: MIT License
docker-compose up
Good afternoon I am working with ngnix as a reverse proxy, and with spring boot to develop api rest, all raising with docker, the question is that I need to work with secure https, for which I create my self-signed certificates as detailed below:
Prepare my certificates with openssl:
#!/bin/bash
echo "Generating an SSL private key to sign your certificate..."
openssl genrsa -des3 -out myssl.key 1024
echo "Generating a Certificate Signing Request..."
openssl req -new -key myssl.key -out myssl.csr
echo "Removing passphrase from key (for nginx)..."
cp myssl.key myssl.key.org
openssl rsa -in myssl.key.org -out myssl.key
rm myssl.key.org
echo "Generating certificate..."
openssl x509 -req -days 365 -in myssl.csr -signkey myssl.key -out myssl.crt
My directory where is my applications and docker-compose yml file:
My Docker Compose:
version: '3'
services:
nginx:
container_name: ngnix
image: nginx:1.13
restart: always
ports:
- 37004:80
- 37005:443
volumes:
- ./nginx-conf.d:/etc/nginx/conf.d
- ./data-cert:/certs
depends_on:
- app
- app2
app:
image: prueba-https
container_name: prueba-https
restart: unless-stopped
build:
context: ./app
dockerfile: Dockerfile
expose:
- "8080"
ports:
- 37006:8080
app2:
image: prueba-https-2
container_name: prueba-https-2
restart: unless-stopped
build:
context: ./app2
dockerfile: Dockerfile
expose:
- "8080"
ports:
- 37007:8080
Internally (not on the host) I am exposing the containers by port 8080, as seen in the yml file, I don't know if this can be done to configure ssl, or if app2 should expose it on port 8081, for example, they would like help me clarify that.
Inside the nginx-conf.d folder I have my app.conf file, which is in the volume defined in my docker-compose yml file:
app.conf
server {
listen *:80;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
ssl on; ssl_certificate /certs/myssl.crt;
ssl_certificate_key /certs/myssl.key;
}
My containers raised
All good so far, but when I am going to test the api rest in postman, with the container that rises on port 37006 everything is fine with https, but with the port that rises on port 37007 I cannot use https:
HTTPS Ok (37006)
Bad HTTPS (37007)
What am I doing wrong?
I am not using domain, in my company the api are handled as I show, using the POST method always
Should I generate a certificate for each application individually?
Should I expose my app2 application on port 8081, example?
I'm totally new to ngnix and I couldn't find a solution to this problem
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.5.8.RELEASE:repackage (default) on project com.hellokoding: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:1.5.8.RELEASE:repackage failed: A required
class was missing while executing org.springframework.boot:spring-boot-maven-plugin:1.5.8.RELEASE:repackage: org/springframework/core/io/support/SpringFactoriesLoader
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.