# Sets the worker threads to the number of CPU cores available in the system for best performance.
# Should be > the number of CPU cores.
# Maximum number of connections = worker_processes * worker_connections
worker_processes auto;

# Maximum number of open files per worker process.
# Should be > worker_connections.
worker_rlimit_nofile 8192;

events {
  # If you need more connections than this, you start optimizing your OS.
  # That's probably the point at which you hire people who are smarter than you as this is *a lot* of requests.
  # Should be < worker_rlimit_nofile.
  worker_connections 8000;
}

# Log errors and warnings to this file
# This is only used when you don't override it on a server{} level
error_log /dev/stderr warn;

# The file storing the process ID of the main process
pid /run/nginx.pid;

# The process is managed in the docker-env
daemon off;

# Free some CPU cycles
timer_resolution 500ms;

http {
    # Specify MIME types for files.
    include       mime.types;
    default_type  application/octet-stream;

    # Update charset_types to match updated mime.types.
    # text/html is always included by charset module.
    charset_types text/css text/plain text/vnd.wap.wml application/javascript application/json application/rss+xml application/xml;

    # Include $http_x_forwarded_for within default format used in log files
    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
                    '$status $body_bytes_sent "$http_referer" '
                    '"$http_user_agent" "$http_x_forwarded_for"';

    # Hide used software
    server_tokens off;

    # Default charset
    charset utf-8;

    # How long to allow each connection to stay idle.
    # Longer values are better for each individual client, particularly for SSL,
    # but means that worker connections are tied up longer.
    keepalive_timeout 20s;

    # Speed up file transfers by using sendfile() to copy directly
    # between descriptors rather than using read()/write().
    # For performance reasons, on FreeBSD systems w/ ZFS
    # this option should be disabled as ZFS's ARC caches
    # frequently used files in RAM by default.
    sendfile        on;

    # Don't send out partial frames; this increases throughput
    # since TCP frames are filled up before being sent out.
    tcp_nopush      on;

    # Allow up to 512 MiB payload, privatebin defaults to 10 MiB.
    client_max_body_size 512M;

    # Load even moar configs
    include /etc/nginx/http.d/*.conf;
}