Vaibhav Ranglani
Vaibhav Ranglani

Reputation: 213

How to forward upstream from nginx to upstream server

I am trying to reverse-proxy an ejabberd connection manager with nginx in docker.

Following is my docker-compose file

version: '2'
services:
  nginx:
    image: nginx
    ports:
      - "80:80"
      - "443:443"
    depends_on:
      - ejabberd
    links:
      - ejabberd
  ejabberd:
    image: ejabberd:16.04
    depends_on:
      - mysql
    ports:
      - "5280:5280"
    links:
      - mysql
  mysql:
    image: mysql:5.6
    ports:
      - "3306:3306"

The images nginx, ejabberd:16.04 and mysql:5.6 are available in my local docker.

Following is my server config file which is included in the nginx.conf file

upstream ejabberd-server {
        server ejabberd:5280;
}
server {
    # regular silverstripe things here

    # location should match your JabberPage::BOSHUrl
    # with a leading slash
    listen 80;
    #server_name oops.hereim.co

    location /http-bind {
        # Local ejabberd with http-bind
        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://ejabberd-server;
    }

}

But when I try to access the url http://192.168.99.102/http-bind

I get the error 404 not found.

Am I missing something in the configuration above?

192.168.99.102 is the IP of my docker machine.

docker-compose exec nginx ping ejabberd

The above command returns a reply.

The upstream has to be setup to host ejabberd as nginx and ejabberd are not on the same ejabberd container.

If you see the docker-compose.yml, the ejabberd and mysql connection works fine and I am able to connect to mysql from ejabberd. But there seems to be some missing piece while connection nginx to ejabberd.

Upvotes: 1

Views: 1933

Answers (2)

Penkey Suresh
Penkey Suresh

Reputation: 5974

Looks like your server part in upstream is a bit wrong.

Can you try server 127.0.0.1:5280; instead of server ejabberd:5280; ?

Upvotes: 0

Vaibhav Ranglani
Vaibhav Ranglani

Reputation: 213

The issue is probably due to an nginx issue. nginx does not pick up .conf files under the /etc/nginx/conf.d directory.

I had to change the file /etc/nginx/sites-enabled/default and enter the location inside that file. This solved my problem for this question.

The next action item is to check why nginx does not read conf file from /etc/nginx/conf.d directory

Upvotes: 1

Related Questions