I have a working docker nginx container with a react app running inside. I did not to suceed adding my ssl-certificates, which are already running in the node.js backend app.
This is how my dockerfile looks like:
FROM nginx
COPY build/ /usr/share/nginx/html
COPY certs/abc.de_ssl_certificate.cer /etc/nginx/certs/
COPY certs/*.abc.de_private_key.key /etc/nginx/certs/
COPY nginx.conf /etc/nginx/conf.d/default.conf
I tried to create an nginx.conf file and copy it to the container automatically, but as soon as I try anything with the config-file, the server is not reachable on the browser. Only the http request gets forwarded to https. I tried something like this:
server {
listen 80;
server_name abc.de;
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl;
server_name abc.de;
ssl_certificate /etc/nginx/certs/abc.de_ssl_certificate.cer;
ssl_certificate_key /etc/nginx/certs/*.abc.de_private_key.key;
location / {
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
2
Answers
I found the problem. The path to the application is not port 3000 as the files are in the folder of nginx itself.
I used this code to proxy pass ssl to and ssl encrypted REST API, but should work as well for you:
As you can see, there are missing settins on your code:
On server block:
And on location:
It should solve the ssl problems (this settings are for a CA validated cert), for a self signed cert use, on location: