feat: custom shell, SSH porta 122 e network_mode host
This commit is contained in:
parent
c3b9316fd2
commit
54f8a4283b
|
|
@ -0,0 +1,84 @@
|
|||
# .bashrc para o container Nginx Pathfinder Proxy
|
||||
|
||||
# Cores para o prompt
|
||||
export PS1='\[\033[01;32m\]\u@pathfinder\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
|
||||
|
||||
# Alias úteis
|
||||
alias ll='ls -lah'
|
||||
alias reload='nginx -s reload'
|
||||
alias test='nginx -t'
|
||||
|
||||
# Vai para a pasta de configurações por padrão
|
||||
cd /etc/nginx/conf.d
|
||||
|
||||
# Função para validar e recarregar o Nginx com feedback em português
|
||||
nginx_ativar() {
|
||||
echo "🔍 Iniciando validação técnica em /etc/nginx/conf.d..."
|
||||
|
||||
# Executa o teste de sintaxe do Nginx
|
||||
OUTPUT=$(nginx -t 2>&1)
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "✅ Sintaxe validada com sucesso! Aplicando alterações..."
|
||||
# Recarrega o serviço de forma segura (sem derrubar conexões)
|
||||
nginx -s reload
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "🚀 Sucesso: O site foi ativado e o Nginx está operando com as novas configurações."
|
||||
else
|
||||
echo "❌ Erro crítico: Falha ao recarregar o processo do Nginx."
|
||||
fi
|
||||
else
|
||||
echo "⚠️ Falha na Validação! As alterações NÃO foram aplicadas."
|
||||
echo "Verifique os detalhes do erro abaixo:"
|
||||
echo "------------------------------------------------------------"
|
||||
echo "$OUTPUT"
|
||||
echo "------------------------------------------------------------"
|
||||
fi
|
||||
}
|
||||
|
||||
# Ferramenta para selecionar e ativar sites do repositório Git
|
||||
nginx_menu() {
|
||||
REPO_URL="https://git.itguys.com.br/joao.goncalves/NgixProxy_Pathfinder.git"
|
||||
TEMP_DIR="/tmp/site_repo"
|
||||
|
||||
echo "🌐 Buscando lista de sites no repositório..."
|
||||
rm -rf "$TEMP_DIR"
|
||||
git clone --depth 1 -b sites-ativos "$REPO_URL" "$TEMP_DIR" &>/dev/null
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "❌ Erro ao conectar ao repositório Git."
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Lista arquivos .conf na pasta conf.d do repo
|
||||
SITES=($(ls "$TEMP_DIR/conf.d"/*.conf 2>/dev/null | xargs -n 1 basename))
|
||||
|
||||
if [ ${#SITES[@]} -eq 0 ]; then
|
||||
echo "⚠️ Nenhum arquivo de site (.conf) encontrado no repositório."
|
||||
return 1
|
||||
fi
|
||||
|
||||
echo "--- Selecione o site para ativar ---"
|
||||
PS3='Escolha o número (ou q para sair): '
|
||||
select SITE in "${SITES[@]}"; do
|
||||
if [[ "$REPLY" == "q" ]]; then
|
||||
echo "Saindo..."
|
||||
break
|
||||
elif [[ -n "$SITE" ]]; then
|
||||
echo "📥 Baixando e ativando $SITE..."
|
||||
cp "$TEMP_DIR/conf.d/$SITE" /etc/nginx/conf.d/
|
||||
nginx_ativar
|
||||
break
|
||||
else
|
||||
echo "Opção inválida."
|
||||
fi
|
||||
done
|
||||
|
||||
rm -rf "$TEMP_DIR"
|
||||
}
|
||||
|
||||
echo "--- Pathfinder Proxy Console ---"
|
||||
echo "Comandos disponíveis:"
|
||||
echo " nginx_ativar - Valida e recarrega as configs"
|
||||
echo " nginx_menu - Busca e ativa sites do Git"
|
||||
echo "--------------------------------"
|
||||
23
Dockerfile
23
Dockerfile
|
|
@ -1,7 +1,13 @@
|
|||
FROM alpine:latest
|
||||
|
||||
# Install NGINX and tools
|
||||
RUN apk add --no-cache nginx nginx-mod-http-brotli nginx-mod-http-headers-more bind-tools openssl curl bash certbot git nano
|
||||
RUN apk add --no-cache nginx nginx-mod-http-brotli nginx-mod-http-headers-more bind-tools openssl curl bash certbot git nano openssh-server
|
||||
|
||||
# Setup SSH
|
||||
RUN mkdir -p /var/run/sshd && \
|
||||
echo "root:root" | chpasswd && \
|
||||
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config && \
|
||||
sed -i 's/#Port 22/Port 122/' /etc/ssh/sshd_config
|
||||
|
||||
# Setup Nginx directories
|
||||
RUN mkdir -p /run/nginx /var/cache/nginx
|
||||
|
|
@ -10,12 +16,15 @@ RUN mkdir -p /run/nginx /var/cache/nginx
|
|||
RUN ln -sf /dev/stdout /var/log/nginx/access.log \
|
||||
&& ln -sf /dev/stderr /var/log/nginx/error.log
|
||||
|
||||
# Copy custom config (defaults, will be overriden by volumes)
|
||||
# COPY nginx.conf /etc/nginx/nginx.conf <-- Removed: Managed in sites-ativos
|
||||
# COPY snippets/ /etc/nginx/snippets/ <-- Removed: Managed in sites-ativos
|
||||
# Copy Entrypoint
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
RUN chmod +x /entrypoint.sh
|
||||
|
||||
# Workdir
|
||||
WORKDIR /etc/nginx/conf.d
|
||||
|
||||
# Expose ports
|
||||
EXPOSE 80 443
|
||||
EXPOSE 80 443 122
|
||||
|
||||
# Start Nginx
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
# Start services
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
|
|
|
|||
|
|
@ -3,15 +3,15 @@ services:
|
|||
build: .
|
||||
container_name: nginx-proxy
|
||||
restart: always
|
||||
network_mode: bridge
|
||||
ports:
|
||||
- "80:80"
|
||||
- "443:443"
|
||||
network_mode: host
|
||||
volumes:
|
||||
# Configurations must be mounted from 'sites-ativos' (Git or Volume)
|
||||
#- ./nginx.conf:/etc/nginx/nginx.conf
|
||||
#- ./conf.d:/etc/nginx/conf.d
|
||||
#- ./snippets:/etc/nginx/snippets
|
||||
# Personalização do Shell
|
||||
- ./.bashrc:/root/.bashrc:ro
|
||||
|
||||
# Mapeamento para persistência e edição direta
|
||||
- ../sites-ativos/nginx.conf:/etc/nginx/nginx.conf
|
||||
- ../sites-ativos/conf.d:/etc/nginx/conf.d
|
||||
- ../sites-ativos/snippets:/etc/nginx/snippets
|
||||
|
||||
# Persistent Data
|
||||
- ./ssl:/etc/nginx/ssl
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Carrega o .bashrc se existir
|
||||
[ -f ~/.bashrc ] && . ~/.bashrc
|
||||
|
||||
# Gera chaves de host SSH se não existirem
|
||||
ssh-keygen -A
|
||||
|
||||
# Inicia o SSH em background
|
||||
/usr/sbin/sshd
|
||||
|
||||
# Inicia o Nginx em foreground
|
||||
echo "🚀 Iniciando Nginx..."
|
||||
exec nginx -g "daemon off;"
|
||||
Loading…
Reference in New Issue