How to forward http request to application running on port 80 with NGINX

The Ubuntu server is running,
Glassfish on port 80(http) & 443(https)
Nginx on port 8080(http) & 8081(https)

The goal is,
www.hostname01.com to access Glassfish,
www.hostname02.com to access Nginx

The question is,
is it possible to do so using Nginx proxy pass configuration? or any other settings?

I see answers that have Nginx running on port 80/443 since that is the default http request goes to, however in my environment the Glassfish was running prior to Nginx and I do not have the authority to modify its settings, thus currently any request goes to Glassfish unless port number is specified.
I am allowed to edit any other server configuration except for the Glassfish instance.

Thanks


Solution 1:

The only way to accomplish this is to bind a second IP address to the network interface and bind Glassfish explicitly to the first IP and nginx to the second IP.
As soon as any application listens to 0.0.0.0:80 the port is blocked for any other application.
As soon as you did this, you can tell nginx to only listen on a specific address using the bind parameter in the listen directive like this: listen 192.0.2.1:80 bind
This is an IP socket topic, not only a configuration topic.