Skip to content

Instantly share code, notes, and snippets.

@mpolinowski
Created November 29, 2022 03:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpolinowski/d7c49fb57753f5fd95dc9d1f260f05e8 to your computer and use it in GitHub Desktop.
Save mpolinowski/d7c49fb57753f5fd95dc9d1f260f05e8 to your computer and use it in GitHub Desktop.
job "ingress_backend_connect" {
datacenters = ["dc1"]
group "nginx_ingress" {
count = 1
network {
mode = "host"
port "http" {
static = "8080"
}
}
service {
name = "ingress-http"
port = "http"
provider = "nomad"
check {
name = "HTTP Health"
port = "http"
path = "/"
type = "http"
protocol = "http"
interval = "30s"
timeout = "2s"
}
}
task "ingress-container" {
driver = "docker"
config {
network_mode = "host"
image = "nginx:alpine"
ports = ["http"]
volumes = [
"local/nginx/nginx.conf:/etc/nginx/nginx.conf",
"local/nginx/default.conf:/etc/nginx/conf.d/default.conf"
]
}
# nginx.conf
template {
data = <<EOH
user nginx;
worker_processes auto;
worker_rlimit_nofile 15000;
pid /var/run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 2048;
multi_accept on;
use epoll;
}
http {
default_type application/octet-stream;
error_log /dev/stdout info;
server_tokens off;
server_names_hash_bucket_size 64;
include /etc/nginx/mime.types;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
charset utf-8;
source_charset utf-8;
charset_types text/xml text/plain text/vnd.wap.wml application/javascript application/rss+xml;
include /etc/nginx/conf.d/default.conf;
}
EOH
destination = "local/nginx/nginx.conf"
}
# default.conf
template {
data = <<EOH
server {
listen 8080;
listen [::]:8080;
server_name _;
location / {
proxy_pass http://127.0.0.1:7777;
}
}
EOH
destination = "local/nginx/default.conf"
}
}
}
group "nginx_backend" {
count = 1
network {
mode = "host"
port "http" {
static = "7777"
}
}
service {
name = "backend-http"
port = "http"
provider = "nomad"
check {
name = "HTTP Health"
port = "http"
path = "/"
type = "http"
protocol = "http"
interval = "30s"
timeout = "2s"
}
}
task "backend-container" {
driver = "docker"
config {
network_mode = "host"
image = "nginx:alpine"
ports = ["http"]
volumes = [
"local/nginx/nginx.conf:/etc/nginx/nginx.conf",
"local/nginx/default.conf:/etc/nginx/conf.d/default.conf",
"local/nginx/index.html:/usr/share/nginx/html/index.html"
]
}
# nginx.conf
template {
data = <<EOH
user nginx;
worker_processes auto;
worker_rlimit_nofile 15000;
pid /var/run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 2048;
multi_accept on;
use epoll;
}
http {
default_type application/octet-stream;
# access_log /var/log/nginx/access.log;
# activate the server access log only when needed
error_log /dev/stdout info;
server_tokens off;
server_names_hash_bucket_size 64;
include /etc/nginx/mime.types;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
charset utf-8;
source_charset utf-8;
charset_types text/xml text/plain text/vnd.wap.wml application/javascript application/rss+xml;
include /etc/nginx/conf.d/default.conf;
}
EOH
destination = "local/nginx/nginx.conf"
}
# default.conf
template {
data = <<EOH
server {
listen 7777 default_server;
listen [::]:7777;
server_name _;
access_log /dev/stdout;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
EOH
destination = "local/nginx/default.conf"
}
# index.html
template {
data = <<EOH
<!DOCTYPE html>
<html>
<head>
<title>Hello Nomad</title>
</head>
<body>
<h1>No Consul Connect...</h1>
<p>¯\_(ツ)_/¯</p>
</body>
</html>
EOH
destination = "local/nginx/index.html"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment