Last active
September 29, 2023 07:42
-
-
Save stefanpejcic/76925a127837820d5a9b1a61c0c0e285 to your computer and use it in GitHub Desktop.
/usr/bin/gunicorn -c /usr/local/panel/gunicorn.config.py app:app
This file contains 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
# Gunicorn configuration file | |
# https://docs.gunicorn.org/en/stable/configure.html#configuration-file | |
# https://docs.gunicorn.org/en/stable/settings.html | |
import multiprocessing | |
from gunicorn.config import Config | |
# Create a Gunicorn configuration object | |
config = Config() | |
# Listen on port 2083 for both HTTP and HTTPS | |
bind = ["0.0.0.0:2083"] | |
backlog = 2048 | |
workers = multiprocessing.cpu_count() * 2 + 1 | |
# Use gevent worker class | |
worker_class = 'gevent' | |
worker_connections = 1000 | |
timeout = 30 | |
graceful_timeout = 30 | |
keepalive = 2 | |
max_requests = 1000 | |
max_requests_jitter = 50 | |
pidfile = 'openpanel' | |
# Middleware for routing based on the hostname | |
def hostname_middleware(environ, start_response): | |
# Check the hostname from the request | |
hostname = environ.get('HTTP_HOST', '') | |
if 'openpanel.co' in hostname: | |
# Use HTTPS on port 2083 | |
environ['wsgi.url_scheme'] = 'https' | |
else: | |
# Use HTTP on port 2083 | |
environ['wsgi.url_scheme'] = 'http' | |
return app(environ, start_response) | |
# SSL settings | |
certfile = '/etc/live/ssl_certificate.crt' | |
keyfile = '/etc/live/ssl_private_key.key' | |
ssl_version = util.ssl.PROTOCOL_TLS | |
def post_fork(server, worker): | |
server.log.info("Worker spawned (pid: %s)", worker.pid) | |
def pre_fork(server, worker): | |
pass | |
def pre_exec(server): | |
server.log.info("Forked child, re-executing.") | |
def when_ready(server): | |
server.log.info("Server is ready. Spawning workers") | |
def worker_int(worker): | |
worker.log.info("worker received INT or QUIT signal") | |
errorlog = '/var/log/openpanel/error.log' | |
loglevel = 'info' | |
accesslog = '/var/log/openpanel/access.log' | |
access_log_format = '%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"' | |
# Application reference | |
app = app:app | |
# Add the hostname middleware | |
application = hostname_middleware | |
# Allow specific IP addresses | |
#config.allow_ip = ['192.168.1.100'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run with
cd /usr/local/panel/ && /usr/bin/gunicorn -c /usr/local/panel/gunicorn_config.py app:app