mzibit
mzibit

Reputation: 93

NGINX: proxy_pass microservices

I have a mesos cluster working in environment test and I set up nginx + nixy for service discovery. It is working fine, but when nginx make a proxy_pass for docker container, I receive a 404 error.

ex: I have a Tomcat container listen in privateip:37130, if I configure proxy_pass for location /, it is working! If i configure for location /service, I get the 404 error code.

Someone have any idea?

My nginx.conf

worker_processes auto;
pid /run/nginx.pid;

events {
    use epoll;
    worker_connections 2048;
    multi_accept on;
}
http {
    add_header X-Proxy  always;
    access_log off;
    error_log /var/log/nginx/error.log warn;
    server_tokens off;
    client_max_body_size 128m;
    proxy_buffer_size 128k;
    proxy_buffers 4 256k;
    proxy_busy_buffers_size 256k;
    proxy_redirect off;
    map $http_upgrade $connection_upgrade {
        default upgrade;
        ''  close;
    }
    # time out settings
    proxy_send_timeout 120;
    proxy_read_timeout 120;
    send_timeout 120;
    keepalive_timeout 10;
    upstream tomcat {
        server 172.30.119.214:31816;
    }

    server {
        listen 80;
        server_name app.org;

        location / {
            return 503;
        }
        location /tomcat/ {
            proxy_set_header HOST $host;
            proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
            proxy_connect_timeout 30;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
            proxy_pass http://tomcat;
        }
    }
}

Upvotes: 0

Views: 500

Answers (1)

Tarun Lalwani
Tarun Lalwani

Reputation: 146580

Change below

proxy_pass http://tomcat;

to

proxy_pass http://tomcat/;

Adding the trailing / would make sure that the /tomcat/ from the location will not be sent to the tomcat service

Upvotes: 3

Related Questions