Skip to content

Instantly share code, notes, and snippets.

@AndreasArne
Last active November 9, 2023 09:04
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 AndreasArne/58374253123a31bb7c32e2b551fe8492 to your computer and use it in GitHub Desktop.
Save AndreasArne/58374253123a31bb7c32e2b551fe8492 to your computer and use it in GitHub Desktop.
Nginx load balancer config templates
http {
upstream app-hosts {
{{ lb_method }};
server {{ groups['appserver'][0] }}:8000;
}
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
# This server accepts all traffic to port 80 and passes it to the upstream.
# Notice that the upstream name and the proxy_pass need to match.
server {
listen 80;
server_name {{ domain_name }} www.{{ domain_name }};
return 301 https://$server_name$request_uri;
#location / {
# proxy_pass http://app-hosts;
#}
}
server {
listen 443 ssl;
server_name {{ domain_name }} www.{{ domain_name }};
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
ssl_certificate /etc/letsencrypt/live/{{ domain_name }}/cert.pem;
ssl_certificate_key /etc/letsencrypt/live/{{ domain_name }}/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
location / {
proxy_pass http://app-hosts;
}
}
}
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
include /etc/nginx/sites-enabled/*;
events {
worker_connections 768;
# multi_accept on;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment