upstream tomcat {
    server tomcat:8080;
}

upstream ghost {
    server ghost:2368;
}

# HTTP
server {
    listen 80                               default_server;
    listen [::]:80                          default_server ipv6only=on;
    server_name                             ${NGINX_HOST};

    error_log                               /var/log/nginx/error.log;
    access_log                              /var/log/nginx/access.log;

    root /app;
    index index.jsp index.html index.htm;

    client_max_body_size                    100M;

    location / {
        root                                /var/www/html;
    }

    ####### Proxies #######
#    # PHP proxy
#    location /board {
#        fastcgi_pass                       php:9001;
#        fastcgi_index                      index.php;
#        include                            fastcgi.conf;
#        root                               /app;
#    }

    # Ghost proxy
    location /blog {
        proxy_pass                          http://ghost;
        proxy_set_header  Host              $http_host;   # required for docker client's sake
        proxy_set_header  X-Real-IP         $remote_addr; # pass on real client's IP
        proxy_set_header  X-Forwarded-For   $proxy_add_x_forwarded_for;
        proxy_set_header  X-Forwarded-Proto $scheme;
        proxy_read_timeout                  900;
    }

    # Tomcat proxy
    location ~ \.jsp$ {
        proxy_set_header X-Forwarded-Host   $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For    $proxy_add_x_forwarded_for;
        proxy_pass                          http://tomcat;
    }
}
