Nginx es uno de los servidores web más rápidos y eficientes para entornos Linux. En esta guía aprenderás a:
- Instalar y configurar Nginx en AlmaLinux
- Habilitar HTTPS con Let’s Encrypt
- Optimizar el rendimiento para producción
- Solucionar errores comunes
🛠️ Instalación de Nginx #
- Instalar desde repositorios
1
sudo dnf install nginx -y
- Iniciar y habilitar el servicio
1
sudo systemctl enable --now nginx
- Verificar instalaciónDeberías ver: HTTP/1.1 200 OK
1
curl -I localhost
📂 Configuración Básica #
Estructura de archivos clave #
Ruta | Propósito |
---|---|
/etc/nginx/nginx.conf | Configuración principal |
/etc/nginx/conf.d/ | Configs de sitios adicionales |
/var/www/html/ | Directorio raíz por defecto |
Ejemplo de configuración mínima #
|
|
Verificar y recargar:
|
|
🔒 Certificado SSL con Let’s Encrypt #
- Instalar Certbot
1
sudo dnf install certbot python3-certbot-nginx -y
- Obtener certificado
1
sudo certbot --nginx -d tusitio.com -d www.tusitio.com
- Renovación automática
Añadir al cron:
1
0 3 \* \* \* /usr/bin/certbot renew --quiet
⚡ Optimización de Rendimiento #
Ajustes recomendados en /etc/nginx/nginx.conf #
|
|
Comandos útiles #
|
|
🚨 Solución de Problemas Comunes #
Error: “Port 80 already in use” #
|
|
Error: “SSL handshake failed” #
Verificar que el puerto 443 esté abierto:
|
|
📊 Comparativa Nginx vs Apache #
Característica | Nginx | Apache |
---|---|---|
Velocidad | Rapido | Lento |
Rendimiento | Alto | Medio |
Consumo RAM | Bajo | Moderado |
Facilidad | Intermedia | Sencilla |
Soporte .htaccess | No | Sí |
📌 Conclusión #
Con esta guía has aprendido a:
- Desplegar Nginx en AlmaLinux
- Configurar sitios virtuales
- Implementar HTTPS automático
- Optimizar para entornos productivos
Comparte