mirror of
https://github.com/lijiejie/eyes.sh.git
synced 2026-09-22 01:30:43 +08:00
@@ -0,0 +1,20 @@
|
|||||||
|
# Compose
|
||||||
|
COMPOSE_PROJECT_NAME=dnslog
|
||||||
|
COMPOSE_HTTP_TIMEOUT=3600
|
||||||
|
DOCKER_CLIENT_TIMEOUT=3600
|
||||||
|
DOCKER_SUBNET=172.16.239.0/24
|
||||||
|
|
||||||
|
# MySQL
|
||||||
|
DB_HOST=mysql
|
||||||
|
DB_PORT=3306
|
||||||
|
DB_USER=root
|
||||||
|
DB_PASSWORD=PucJ86KwPz9sfigZzlGa
|
||||||
|
DB_NAME=dnslog
|
||||||
|
|
||||||
|
# DNSLog
|
||||||
|
SECRET_KEY=GeqwBTQCvK4Yg2VneExUxtNGuLR4pQYy6xduMfPAM4oJgdqQ12
|
||||||
|
DNS_DOMAIN=eyes.sh
|
||||||
|
ADMIN_DOMAIN=eyes.sh
|
||||||
|
NS1_DOMAIN=eyes_dns1.lijiejie.com
|
||||||
|
NS2_DOMAIN=eyes_dns2.lijiejie.com
|
||||||
|
SERVER_IP=123.123.123.123
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
FROM python:3.8
|
||||||
|
|
||||||
|
ENV TZ Asia/Shanghai
|
||||||
|
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
||||||
|
|
||||||
|
ADD . /dnslog
|
||||||
|
RUN pip install -r /dnslog/requirements.txt
|
||||||
|
RUN chmod +x /dnslog/docker-entrypoint.sh
|
||||||
|
|
||||||
|
WORKDIR /dnslog
|
||||||
|
EXPOSE 53
|
||||||
|
|
||||||
|
ENTRYPOINT ["/dnslog/docker-entrypoint.sh"]
|
||||||
|
|
||||||
|
# Install nginx
|
||||||
|
RUN apt update -y
|
||||||
|
RUN apt-get install -y \
|
||||||
|
ca-certificates \
|
||||||
|
nginx \
|
||||||
|
gettext-base \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
RUN ln -sf /dev/stdout /var/log/nginx/access.log \
|
||||||
|
&& ln -sf /dev/stderr /var/log/nginx/error.log
|
||||||
|
|
||||||
|
RUN cp /dnslog/dnslog_nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
|
|
||||||
|
EXPOSE 80
|
||||||
|
|
||||||
|
CMD ["nginx", "-g", "daemon off;"]
|
||||||
+22
-14
@@ -6,7 +6,7 @@ from django.utils.translation import gettext_lazy as _
|
|||||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
# SECURITY WARNING: keep the secret key used in production secret!
|
# SECURITY WARNING: keep the secret key used in production secret!
|
||||||
SECRET_KEY = '#ma=s-l!2obwj%h-6uu^sbw+4%i2w79%v3^ill62k3&7tjf5dc'
|
SECRET_KEY = os.getenv("SECRET_KEY", "#ma=s-l!2obwj%h-6uu^sbw+4%i2w79%v3^ill62k3&7tjf5dc")
|
||||||
|
|
||||||
DEBUG = False
|
DEBUG = False
|
||||||
|
|
||||||
@@ -15,6 +15,13 @@ ALLOWED_HOSTS = ['*']
|
|||||||
# SECURE_SSL_REDIRECT = True
|
# SECURE_SSL_REDIRECT = True
|
||||||
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
|
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
|
||||||
|
|
||||||
|
# CSRF
|
||||||
|
CSRF_TRUSTED_ORIGINS = [
|
||||||
|
"http://localhost:8080", "http://localhost",
|
||||||
|
"http://%s" % (os.getenv("ADMIN_DOMAIN", "eyes.sh")),
|
||||||
|
"https://%s" % (os.getenv("ADMIN_DOMAIN", "eyes.sh"))
|
||||||
|
]
|
||||||
|
|
||||||
INSTALLED_APPS = (
|
INSTALLED_APPS = (
|
||||||
'django.contrib.admin',
|
'django.contrib.admin',
|
||||||
'django.contrib.auth',
|
'django.contrib.auth',
|
||||||
@@ -59,10 +66,10 @@ WSGI_APPLICATION = 'dnslog.wsgi.application'
|
|||||||
DATABASES = {
|
DATABASES = {
|
||||||
'default': {
|
'default': {
|
||||||
'ENGINE': 'django.db.backends.mysql',
|
'ENGINE': 'django.db.backends.mysql',
|
||||||
'NAME': 'DB_NAME',
|
'NAME': os.getenv('DB_NAME', 'mysql'),
|
||||||
'USER': 'DB_USER',
|
'USER': os.getenv('DB_USER', 'root'),
|
||||||
'PASSWORD': 'DB_PASSWORD',
|
'PASSWORD': os.getenv('DB_PASSWORD', 'root'),
|
||||||
'HOST': 'DB_HOST',
|
'HOST': os.getenv('DB_HOST', 'localhost'),
|
||||||
'PORT': '3306'
|
'PORT': '3306'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -80,26 +87,26 @@ LANGUAGES = (
|
|||||||
('en', _('English')),
|
('en', _('English')),
|
||||||
)
|
)
|
||||||
|
|
||||||
LOCALE_PATHS = (os.path.join(BASE_DIR, 'locale'),)
|
LOCALE_PATHS = (os.path.join(BASE_DIR, 'locale'), )
|
||||||
|
|
||||||
STATIC_URL = '/static/'
|
STATIC_URL = '/static/'
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)
|
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'), )
|
||||||
else:
|
else:
|
||||||
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
|
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
|
||||||
|
|
||||||
# 用于DNS记录的域名
|
# 用于DNS记录的域名
|
||||||
DNS_DOMAIN = 'eyes.sh'
|
DNS_DOMAIN = os.getenv('DNS_DOMAIN', 'eyes.sh')
|
||||||
|
|
||||||
# 管理后台域名
|
# 管理后台域名
|
||||||
ADMIN_DOMAIN = ['eyes.sh', 'www.eyes.sh']
|
ADMIN_DOMAIN = os.getenv('ADMIN_DOMAIN', 'eyes.sh')
|
||||||
|
|
||||||
# NS域名
|
# NS域名
|
||||||
NS1_DOMAIN = 'eyes_dns1.lijiejie.com'
|
NS1_DOMAIN = os.getenv('NS1_DOMAIN', 'eyes_dns1.lijiejie.com')
|
||||||
NS2_DOMAIN = 'eyes_dns2.lijiejie.com'
|
NS2_DOMAIN = os.getenv('NS2_DOMAIN', 'eyes_dns1.lijiejie.com')
|
||||||
|
|
||||||
# 服务器外网地址
|
# 服务器外网地址
|
||||||
SERVER_IP = '123.123.123.123'
|
SERVER_IP = os.getenv('SERVER_IP', '123.123.123.123')
|
||||||
|
|
||||||
if not DEBUG:
|
if not DEBUG:
|
||||||
LOGGING = {}
|
LOGGING = {}
|
||||||
@@ -110,7 +117,8 @@ else:
|
|||||||
'disable_existing_loggers': True,
|
'disable_existing_loggers': True,
|
||||||
'formatters': {
|
'formatters': {
|
||||||
'verbose': {
|
'verbose': {
|
||||||
'format': "[%(asctime)s] %(levelname)s [ %(filename)s] [line %(lineno)s] %(message)s",
|
'format':
|
||||||
|
"[%(asctime)s] %(levelname)s [ %(filename)s] [line %(lineno)s] %(message)s",
|
||||||
'datefmt': "%d/%b/%Y %H:%M:%S"
|
'datefmt': "%d/%b/%Y %H:%M:%S"
|
||||||
},
|
},
|
||||||
'simple': {
|
'simple': {
|
||||||
@@ -137,4 +145,4 @@ else:
|
|||||||
'level': 'CRITICAL',
|
'level': 'CRITICAL',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
+20
-14
@@ -1,18 +1,24 @@
|
|||||||
server {
|
server {
|
||||||
listen 80;
|
listen 80;
|
||||||
server_name eyes.sh www.eyes.sh *.eyes.sh;
|
server_name localhost $ADMIN_DOMAI;
|
||||||
uwsgi_pass_request_headers on;
|
uwsgi_pass_request_headers on;
|
||||||
|
|
||||||
location = /favicon.ico { access_log off; log_not_found off; }
|
if ($request_uri ~* "^/$") {
|
||||||
location /static/ {
|
return 302 $scheme://$http_host/login;
|
||||||
alias /dnslog/static/;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
location / {
|
location = /favicon.ico {
|
||||||
proxy_set_header Host $host;
|
access_log off; log_not_found off;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
}
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
location /static/ {
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
alias /dnslog/static/;
|
||||||
proxy_pass http://127.0.0.1:8000;
|
}
|
||||||
}
|
|
||||||
|
location / {
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
proxy_pass http://127.0.0.1:8000;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
version: '3'
|
||||||
|
|
||||||
|
services:
|
||||||
|
mysql:
|
||||||
|
image: mariadb:10.6
|
||||||
|
container_name: mysql
|
||||||
|
restart: always
|
||||||
|
command: --character-set-server=utf8 --collation-server=utf8_general_ci
|
||||||
|
environment:
|
||||||
|
DB_USER: $DB_USER
|
||||||
|
DB_PORT: $DB_PORT
|
||||||
|
MARIADB_ROOT_PASSWORD: $DB_PASSWORD
|
||||||
|
MARIADB_DATABASE: $DB_NAME
|
||||||
|
healthcheck:
|
||||||
|
test: "mysql -h127.0.0.1 -P$$DB_PORT -u$$DB_USER -p$$MARIADB_ROOT_PASSWORD -e 'SHOW DATABASES;'"
|
||||||
|
interval: 10s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 3
|
||||||
|
start_period: 30s
|
||||||
|
networks:
|
||||||
|
- net
|
||||||
|
dnslog:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
image: dnslog
|
||||||
|
container_name: dnslog
|
||||||
|
restart: always
|
||||||
|
environment:
|
||||||
|
DB_HOST: $DB_HOST
|
||||||
|
DB_PORT: $DB_PORT
|
||||||
|
DB_USER: $DB_USER
|
||||||
|
DB_PASSWORD: $DB_PASSWORD
|
||||||
|
DB_NAME: $DB_NAME
|
||||||
|
SECRET_KEY: $SECRET_KEY
|
||||||
|
DNS_DOMAIN: $DNS_DOMAIN
|
||||||
|
ADMIN_DOMAIN: $ADMIN_DOMAIN
|
||||||
|
NS1_DOMAIN: $NS1_DOMAIN
|
||||||
|
NS2_DOMAIN: $NS2_DOMAIN
|
||||||
|
SERVER_IP: $SERVER_IP
|
||||||
|
depends_on:
|
||||||
|
- mysql
|
||||||
|
ports:
|
||||||
|
- 53:53/tcp
|
||||||
|
- 53:53/udp
|
||||||
|
- 8080:80/tcp
|
||||||
|
healthcheck:
|
||||||
|
test: "wget -nv -t1 --spider http://localhost/login --no-check-certificate > /dev/null"
|
||||||
|
interval: 10s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 3
|
||||||
|
start_period: 30s
|
||||||
|
networks:
|
||||||
|
- net
|
||||||
|
|
||||||
|
networks:
|
||||||
|
net:
|
||||||
|
driver: bridge
|
||||||
|
ipam:
|
||||||
|
driver: default
|
||||||
|
config:
|
||||||
|
- subnet: $DOCKER_SUBNET
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
#! /usr/bin/env sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
python /dnslog/manage.py makemigrations logview
|
||||||
|
python /dnslog/manage.py migrate
|
||||||
|
python /dnslog/manage.py collectstatic --noinput
|
||||||
|
|
||||||
|
# Run nginx
|
||||||
|
nginx_count=`ps aux|grep nginx|grep -v grep|wc -l`
|
||||||
|
if [ $nginx_count -eq 0 ]; then
|
||||||
|
nginx -g 'daemon off;' &
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Run zoneresolver.py
|
||||||
|
zoneresolver_count=`ps aux|grep zoneresolver|grep -v grep|wc -l`
|
||||||
|
if [ $zoneresolver_count -eq 0 ]; then
|
||||||
|
python /dnslog/zoneresolver.py &
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Run gunicorn
|
||||||
|
gunicorn_count=`ps aux|grep gunicorn|grep -v grep|wc -l`
|
||||||
|
if [ $gunicorn_count -eq 0 ]; then
|
||||||
|
gunicorn --workers 5 --bind 0.0.0.0:8000 dnslog.wsgi:application --daemon
|
||||||
|
fi
|
||||||
|
|
||||||
|
exec "$@"
|
||||||
Reference in New Issue
Block a user