I am a developer and a beginner with Ngnix.
I try to enable ssl
so that I just can develop with htpps on my local.
I made a minimal example trying to keep it simple pushed my trial to my Git repo.
https://github.com/cptuulia/ngnix-ssl/tree/main
I have seen this example on many sites, but I cannot make it to work.
Can anybody help with this?
With this code I expect that when build and run my container by docker compose up and then open the link
https://tom.dev:8000
I should see
It works!
But I see
Your connection is not private Attackers might be trying to steal your information from tom.dev (for example, passwords, messages, or credit cards). Learn more NET::ERR_CERT_AUTHORITY_INVALID
With curl I see some more information:
curl https://tom.dev:8000 -verbose
* Trying 127.0.0.1:8000...
* Connected to tom.dev (127.0.0.1) port 8000
* ALPN: curl offers h2,http/1.1
* (304) (OUT), TLS handshake, Client hello (1):
* CAfile: /etc/ssl/cert.pem
* CApath: none
* LibreSSL/3.3.6: error:1404B42E:SSL routines:ST_CONNECT:tlsv1 alert protocol version
* Closing connection
curl: (35) LibreSSL/3.3.6: error:1404B42E:SSL routines:ST_CONNECT:tlsv1 alert protocol version
Files
- https://github.com/cptuulia/ngnix-ssl/blob/main/docker-compose.yml
version: '3'
services:
nginx:
container_name: nginx-ssl
image: nginx
ports:
- 8000:80
- 443:443
volumes:
- .:/var/www
- .docker/nginx/nginx.conf:/etc/nginx/nginx.conf
- .docker/nginx/certs/tom.dev.crt:/etc/nginx/ssl/tom.dev.crt
- .docker/nginx/certs/tom.dev.key:/etc/nginx/ssl/tom.dev.key
- https://github.com/cptuulia/ngnix-ssl/blob/main/.docker/nginx/nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {}
http {
include /etc/nginx/mime.types;
server {
listen 80;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl ;
server_name tom.dev;
ssl_certificate /etc/nginx/ssl/tom.dev.crt;
ssl_certificate_key /etc/nginx/ssl/tom.dev.key;
location / {
root /var/www/;
index index.html;
try_files $uri $uri/ /index.html;
}
}
}
Certificates
I have tried with both of the methods, but I always get the same error. I am not sure wich is te correct one and if my configuration is OK.
mkcert
cd .docker/nginx/certscd
mkcert "*.tom.dev"
openssl
cd .docker/nginx/certs
openssl req -x509 -nodes -new -sha256 -days 1024 -newkey rsa:2048 -keyout tom.dev.key -out tom.dev.pem -subj "/C=US/CN=Example-Root-CA"
openssl x509 -outform pem -in tom.dev.pem -out tom.dev.crt
t t is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.