2

Through Jelastic's dashboard, I created this:

enter image description here

I just clicked "New environment", then I selected nodejs. I added a docker image (of mailhog).

Now, I would like that port 80 of my environment serves the nodejs application. This is by default so. Therefore nothing to do.

In addition to this, I would like port 8080 (or any other port than 80, like port 5000 for example) of my environment serves mailhog, hosted on the docker image. To do that, I added the following lines to the nginx-jelastic.conf (right after the first server serving the nodejs app):

server {
                listen *:8080;
                listen [::]:8080;
                server_name  _;

                 location / {
                        proxy_pass http://mailhog_upstream;
                }
        }

where I have also defined mailhog_upstream like this:

upstream mailhog_upstream{
server 10.102.8.215;   ### DEFUPPROTO for common ###
    sticky path=/; keepalive 100;
}

If I now browse my environment's 8080 port, then I see ... the nodejs app. If I try any other port than 80 or 8080, I see nothing. Putting another server_name doesn't help. I tried several things but nothing seems to work. Why is that? What am I doing wrong here?

Then I tried to get rid of the above mailhog_upstream and instead write

server {
    listen       *:5000;
    listen       [::]:5000;
    server_name  _;

    location / {
        proxy_pass http://10.102.8.215;
    }
}

Browsing the environment's port 5000 doesn't work either.

If I replace the IP of the nodejs' app with that of my mailhog service, then mailhog runs on port 80. I don't understand how I can make the nodejs app run on port 80 and the mailhog service on port 5000 (or any other port than 80).

Could someone enlighten me please?

After all those failures, I tried another ansatz. Assume the path my env is example.com/. What I've tried above is to get mailhog to work upon calling example.com:5000, which I failed doing. Then I tried to make mailhog available through a call to example.com/mailhog. In order to do that, I got rid of all my modifications above and completed the current server in nginx-jelastic.conf with

location /mailhog {
                    proxy_pass http://10.102.8.96:8025/;
                    add_header Set-Cookie "SRVGROUP=$group; path=/";
                }

That works in the sense that if I know browse example.com/mailhog, then I get something on the page, but not exactly what I want: it's the mailhog's page without any styling. Also, when I call mailhog's API through example.com/mailhog/api/v2/messages, I get a successful response without body, when I should've received

{"total":0,"count":0,"start":0,"items":[]}

What am I doing wrong this time?

Edit

To be more explicit, I put the following manifest that exhibits the second problem with the nginx location.

Laurent Michel
  • 1,069
  • 3
  • 14
  • 29

2 Answers2

1

Full locations list for your case is a following: (please pay attention to URIs in upstreams, they are different)

location /mailhog { proxy_pass http://172.25.2.128:8025/; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "    upgrade"; }
location /mailhog/api { proxy_pass http://172.25.2.128:8025/api; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "    upgrade"; }

location /css { proxy_pass http://172.25.2.128:8025; }
location /js { proxy_pass http://172.25.2.128:8025; }
location /images { proxy_pass http://172.25.2.128:8025; }

that works for me with your application

# curl 172.25.2.127/mailhog/api/v2/messages
{"total":0,"count":0,"start":0,"items":[]}
Ihor Kolodyuk
  • 466
  • 2
  • 5
  • 1
    It is working for me. You get get rid of the whole "proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade";" as it is inherited from the base configuration. Thanks for that insight! – Laurent Michel Oct 19 '19 at 10:01
0

The following ports are opened by default: 80, 8080, 8686, 8443, 4848, 4949, 7979.

Additional ports can be opened using:

  • endpoints - maps the container internal port to random external via Jelastic Shared LB
  • Public IP - provides a direct access to all ports of your container

Read more in the following article: "Container configuration - Ports". This one may also be useful:"Public IP vs Shared Load Balancer"

Virtuozzo
  • 1,993
  • 1
  • 10
  • 13
  • And what about the second option of making `/mailhog` available? why isn't it working? – Laurent Michel Oct 06 '19 at 13:59
  • Could you please clarify the question? MailHog in your docker is currently running on ports 1025,8025. – Virtuozzo Oct 06 '19 at 14:16
  • Mailhog in my docker is currently running on ports 1025, 8025. But I don't want to access it via its own node, I want to access mailhog through my nginx reverse proxy. As far as I know, there are two possibilities: either I open a port on nginx and redirect that port in such a way that it calls mailhog's api or I define a location on nginx and redirect that location in such a way that it calls mailhog's api. In the latter case, I could just curl `example.com/mailhog/api/v2/messages` to get all the messages. That is precisely what is not working. – Laurent Michel Oct 07 '19 at 06:28
  • Following config in nginx-jelastic.conf should work for that case: location /mailhog/ { proxy_pass http://10.102.8.96:8025; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } https://docs.jelastic.com/websockets – Virtuozzo Oct 08 '19 at 04:43
  • In fact, that's the same as putting `location /mailhog { proxy_pass http://10.102.8.96:8025; }` under the `#USERLOCATIONS` because the other commands are already written before the first location. For some reason, that doesn't work either. I get a "404 page not found" when I browse `example.com/mailhog` in that case. If I open the mailhog node in a browser, however, it works. – Laurent Michel Oct 08 '19 at 18:52
  • I have edited my original post and added it a manifest showing exactly what the problem is with the nginx location. You can install that manifest and see what happens. – Laurent Michel Oct 10 '19 at 05:03