Skip to content

Enhancement: Ngnix Templates  #11

@arky

Description

@arky

Newer version Nginix (1.9 or later) allow use of variable substitution using nginux templates

Docker-compose web service

  webserver:
    image: nginx:latest
    volumes:
      - ./files/nginx/templates:/etc/nginx/templates
    depends_on:
      - backend
      - frontend
    ports:
      - "80:80"
    environment:
      - NGINX_HOST=example.com 

Nginx Template

/files/nginx/templates/default.conf.template

upstream backend {
  server backend:8080;
}
upstream frontend {
  server frontend:3000;
}


server {
  listen 80  default_server;
  server_name  ${NGINX_HOST};

  location ~ /\+\+api\+\+($|/.*) {
      rewrite ^/\+\+api\+\+($|/.*) /VirtualHostBase/http/$server_name/Plone/++api++/VirtualHostRoot/$1 break;
      proxy_pass http://backend;
  }

  location ~ / {
      location ~* \.(js|jsx|css|less|swf|eot|ttf|otf|woff|woff2)$ {
          add_header Cache-Control "public";
          expires +1y;
          proxy_pass http://frontend;
      }
      location ~* static.*\.(ico|jpg|jpeg|png|gif|svg)$ {
          add_header Cache-Control "public";
          expires +1y;
          proxy_pass http://frontend;
      }

      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;
      proxy_redirect http:// https://;
      proxy_pass http://frontend;
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions