From 222f40426aa25c15b0a6798d80502fcda9bf793d Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Thu, 21 Sep 2023 16:44:07 -0500 Subject: [PATCH] nginx: Deploy nginx in a container --- nginx.conf | 76 +++++++++++++++++++++++++++++++++++++++++++++++++ nginx.container | 22 ++++++++++++++ nginx.yaml | 17 +++++++++++ 3 files changed, 115 insertions(+) create mode 100644 nginx.conf create mode 100644 nginx.container create mode 100644 nginx.yaml diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..4830703 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,76 @@ +worker_processes auto; + +error_log /var/log/nginx/error.log notice; +pid /var/run/nginx.pid; + + +events { + worker_connections 1024; +} + +http { + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + # Load modular configuration files from the /etc/nginx/conf.d directory. + # See http://nginx.org/en/docs/ngx_core_module.html#include + # for more information. + include /etc/nginx/conf.d/*.conf; + + server { + listen 80 default_server; + listen [::]:80 default_server; + server_name _; + root /usr/share/nginx/html; + + return 301 https://$host$request_uri; + + error_page 404 /404.html; + location = /40x.html { + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + } + } + +# Settings for a TLS enabled server. + + server { + listen 443 ssl http2 default_server; + listen [::]:443 ssl http2 default_server; + server_name _; + root /usr/share/nginx/html; + + ssl_certificate "/etc/pki/nginx/server.crt"; + ssl_certificate_key "/etc/pki/nginx/private/server.key"; + ssl_session_cache shared:SSL:1m; + ssl_session_timeout 10m; + ssl_ciphers TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256:TLS_AES_128_CCM_SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES256-CCM:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-CCM:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:AES256-GCM-SHA384:AES256-CCM:AES128-GCM-SHA256:AES128-CCM:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES256-CCM:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-CCM:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:PSK-AES256-GCM-SHA384:PSK-CHACHA20-POLY1305:PSK-AES256-CCM:PSK-AES128-GCM-SHA256:PSK-AES128-CCM:PSK-AES256-CBC-SHA:PSK-AES128-CBC-SHA256:PSK-AES128-CBC-SHA:DHE-PSK-AES256-GCM-SHA384:DHE-PSK-CHACHA20-POLY1305:DHE-PSK-AES256-CCM:DHE-PSK-AES128-GCM-SHA256:DHE-PSK-AES128-CCM:DHE-PSK-AES256-CBC-SHA:DHE-PSK-AES128-CBC-SHA256:DHE-PSK-AES128-CBC-SHA:ECDHE-PSK-CHACHA20-POLY1305:ECDHE-PSK-AES256-CBC-SHA:ECDHE-PSK-AES128-CBC-SHA256:ECDHE-PSK-AES128-CBC-SHA:RSA-PSK-AES256-GCM-SHA384:RSA-PSK-CHACHA20-POLY1305:RSA-PSK-AES128-GCM-SHA256:RSA-PSK-AES256-CBC-SHA:RSA-PSK-AES128-CBC-SHA256:RSA-PSK-AES128-CBC-SHA; + ssl_prefer_server_ciphers on; + + # Load configuration files for the default server block. + include /etc/nginx/default.d/*.conf; + + error_page 404 /404.html; + location = /40x.html { + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + } + } + +} diff --git a/nginx.container b/nginx.container new file mode 100644 index 0000000..88dfbaa --- /dev/null +++ b/nginx.container @@ -0,0 +1,22 @@ +[Unit] +Description=nginx +Wants=network.target +After=network.target + +[Container] +Image=docker.io/library/nginx:1.25 +User=101 +Group=101 +Volume=%E/nginx:/etc/nginx:ro +Volume=%E/pki/nginx:/etc/pki/nginx:ro +Tmpfs=/var/cache/nginx +Tmpfs=/var/run/nginx +ReadOnly=true +AddCapability=CAP_NET_BIND_SERVICE +Network=host + +[Service] +Restart=always + +[Install] +WantedBy=multi-user.target diff --git a/nginx.yaml b/nginx.yaml new file mode 100644 index 0000000..2ea8ff0 --- /dev/null +++ b/nginx.yaml @@ -0,0 +1,17 @@ +variant: fcos +version: 1.4.0 + +storage: + files: + - path: /etc/containers/systemd/nginx.container + mode: 0644 + contents: + local: nginx.container + - path: /etc/nginx/nginx.conf + mode: 0644 + contents: + local: nginx.conf + directories: + - path: /etc/nginx/conf.d + - path: /etc/nginx/default.d + - path: /etc/pki/nginx