Last active
December 9, 2024 19:29
-
-
Save aleduca/0780adfecfd46a90e4b92c5dd646f6b2 to your computer and use it in GitHub Desktop.
Generate docker ssl certificate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://github.com/openssl/openssl | |
1 - Baixar o Strawberry | |
- Já é colocado no path das variáveis de ambiente, então tenho acesso no terminal ao Perl. | |
2 - Baixar o openSSL | |
3 - Instalar o openSSL com o perl através do comando "perl Configure VC-WIN64A" | |
4 - Seguir os passos abaixo. | |
4a. Gerar a chave privada | |
openssl genrsa -out private.key 2048 | |
4b. Solicitação de assinatura | |
# No Linux não precisa do -config | |
openssl req -new -key private.key -out request.csr -config "C:\tools\openssl\apps\openssl.cnf" | |
4c. Certificado autoassinado com validade de 365 dias | |
openssl x509 -req -days 365 -in request.csr -signkey private.key -out certificate.crt | |
5 - Colocar no Dockerfile do nginx. | |
COPY certificate.crt /etc/nginx/certificate.crt | |
COPY private.key /etc/nginx/private.key | |
6 - Colocar porta 443 no nginx do compose.yml. | |
ports: | |
- "443:443" # Porta SSL | |
- "80:80" | |
7 - No default.conf redirecionar para o https e colocar o certificado e private key. | |
server { | |
listen 80; | |
server_name project1.test; # Opcional, mas recomendado | |
location / { | |
return 301 https://$host$request_uri; # Redireciona para HTTPS | |
} | |
} | |
# Servidor HTTPS com SSL configurado | |
server { | |
listen 443 ssl; # Escuta na porta 443 para HTTPS | |
server_name project1.test; | |
root /var/www/html/public; | |
ssl_certificate /etc/nginx/certificate.crt; # Caminho para o certificado SSL | |
ssl_certificate_key /etc/nginx/private.key; # Caminho para a chave privada | |
ssl_protocols TLSv1.2 TLSv1.3; # Protocolos SSL suportados | |
ssl_ciphers HIGH:!aNULL:!MD5; # Conjunto de cifras recomendadas | |
index index.php; | |
error_log /var/log/nginx/error.log; | |
access_log /var/log/nginx/access.log; | |
error_page 404 /index.php; | |
location ~ \.php$ { | |
try_files $uri =404; | |
fastcgi_pass project1_php_fpm:9000; | |
fastcgi_index index.php; | |
include fastcgi_params; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
} | |
location / { | |
try_files $uri $uri/ /index.php?$query_string; | |
gzip_static on; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment