diff --git a/bastebin.nginx.conf b/bastebin.nginx.conf new file mode 100644 index 0000000..2136b02 --- /dev/null +++ b/bastebin.nginx.conf @@ -0,0 +1,40 @@ +server { + listen 80; + server_name bastebin.com www.bastebin.com; + + # Static files serving - offload from Flask/Gunicorn + location /static/ { + alias /home/colby/projects/bastebin/static/; + expires 30d; + add_header Cache-Control "public, no-transform"; + } + + # Proxy all other requests to Gunicorn + location / { + proxy_pass http://127.0.0.1:5500; + + # Standard proxy headers + 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; + + # Timeouts and keeping connections alive + proxy_http_version 1.1; + proxy_set_header Connection ""; + proxy_connect_timeout 90; + proxy_send_timeout 90; + proxy_read_timeout 90; + + # Max payload size (matching 2MB config or slightly above) + client_max_body_size 5M; + + # Buffer settings + proxy_buffers 16 16k; + proxy_buffer_size 32k; + } + + # Log files - ensure these directories exist or use /var/log/nginx + access_log /var/log/nginx/bastebin.access.log; + error_log /var/log/nginx/bastebin.error.log; +} diff --git a/config.json b/config.json index 1a4f492..ba11e66 100644 --- a/config.json +++ b/config.json @@ -11,7 +11,7 @@ "server": { "host": "0.0.0.0", - "port": 5000, + "port": 5500, "debug": false, "secret_key": "ce81867ddcc16729b42d7ae0564140e6bcc83bcf5dbbe77b7e5b6c5aa4199347" }, diff --git a/production.py b/production.py index 9ca815d..46a7851 100644 --- a/production.py +++ b/production.py @@ -10,6 +10,7 @@ Usage: """ import argparse +import json import multiprocessing import os import signal @@ -168,13 +169,42 @@ def _build_parser() -> argparse.ArgumentParser: def main() -> None: + # 1. Load config for defaults + config_path = os.path.join(BASE_DIR, 'config.json') + config = {} + if os.path.exists(config_path): + try: + with open(config_path, 'r') as f: + config = json.load(f) + except (json.JSONDecodeError, IOError): + pass + + server_cfg = config.get('server', {}) + default_host = server_cfg.get('host', '0.0.0.0') + default_port = server_cfg.get('port', 5000) + + # 2. Parse arguments parser = _build_parser() args = parser.parse_args() + # 3. Resolve merge (CLI > config > absolute defaults) default_workers = max(2, multiprocessing.cpu_count() + 1) + + # Check if user provided CLI arguments. + # args.host and args.port always have values because of 'default' in ArgumentParser. + # We'll re-parse or check the sys.argv. + + host = default_host + port = default_port + + # Simple check: if '--host' or '--port' is in sys.argv, use the arg value. + # Otherwise, use the config value. + if '--host' in sys.argv: + host = args.host + if '--port' in sys.argv: + port = args.port + workers = getattr(args, 'workers', None) or default_workers - host = getattr(args, 'host', '0.0.0.0') - port = getattr(args, 'port', 5000) if args.command == 'start': cmd_start(host, port, workers)