Front Tomcat with NGINX - tsgrp/HPI GitHub Wiki

NGINX Example

The below configuration assumes an Alfresco server running on port 8080 and an OpenAnnotate Tomcat server running on port 9080. The nginx server is configured to run on port 8888.

Important notes:

  • On the proxy_pass configuration for the /alfresco/ location, the lack of a / following http://127.0.0.1:8080 is important as this will allow the full URL to be redirected (including URL params).
  • proxy_pass configurations should use fully qualified IPs instead of hostnames if you want to avoid IPv4 vs IPv6 resolving delays.
worker_processes  1;

events {
    worker_connections  1024;
}

http {
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;

    server {
            listen                          8888;
            server_name                     dev-platform-proxy;

            set  $allowOriginSite *;

            gzip                            on;
            gzip_min_length                 1000;
            gzip_proxied                    expired no-cache no-store private auth;
            underscores_in_headers          on;
            proxy_pass_request_headers      on;
            proxy_pass_header  Set-Cookie;

            location /alfresco/ {
                proxy_pass  http://127.0.0.1:8080;
                proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
                proxy_redirect off;
                proxy_buffering off;
                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_pass_header  Set-Cookie;
            }

	    location /OpenAnnotate/ {
		proxy_pass http://127.0.0.1:9080/OpenAnnotate/;
		proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
		proxy_redirect off;
		proxy_buffering off;
		proxy_set_header	Host		$http_host;
		proxy_set_header	X-Real-IP	$remote_addr;
		proxy_set_header	X-Forwarded-For	$proxy_add_x_forwarded_for;
		proxy_pass_header  Set-Cookie;
		proxy_pass_request_headers	on;
	    }
    }
}