简体   繁体   中英

Nginx reverse proxy - Internal servers separated by trailing slash

I'm a newbie at Nginx, and have been searching a lot for the right answer to my question, but couldn't find it; not because it is not there, but my newbie condition limits me to adapt a generic solution to my issue.

The situation is this: I have a Mantis Bug Tracker in my private LAN ( http://10.111.111.12 ). On the other hand, i have an OwnCloud website also on my LAN (IP 10.111.111.5), with URL http://10.111.111.5/owncloud/ .

What i want to do is to deploy a Nginx Reverse Proxy that handles all requests from Internet at publicdomain.com, and use trailing slash for each internal webserver. The desired result would be:

http://www.publicdomain.com/bugtracker -> redirects to http://10.111.111.12/index.php http://www.publicdomain.com/cloud -> redirects to http://10.111.111.5/owncloud/ (note that "cloud" is preferred over "owncloud")

On the future, it is necessary to continue using trailing slash for other web servers to be deployed.

Questions are: is this scenario possible? if so, is it enough with configuring nginx or I have to reconfigure internal web servers as well?

I really appreciate your help, by indicating me a possible solution or pointing me to the right direction on previous posts.

Thanks a lot in advance.

Yes it is possible to achieve such configuration and it's commonly used when NGINX is acting as a reverse proxy. You can use this configuration as an inspiration for building your own:

upstream bugtracker {
  server 10.111.111.12;
}

upstream cloudupstream {
  server 10.111.111.5;
}

server {
  listen 80;
  location /bugtracker/{
    proxy_pass http://bugtracker;
  }
  location /cloud/{
    proxy_pass http://cloudupstream/owncloud;
  }
}

What's happening over here is that nginx will be listening on port 80 and as soon as a request comes for path /bugtracker, it will automatically route the request to the upstream server mentioned above. Using this you can add as many upstream servers and location blocks as you want. Reference: http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass

Thanks a lot Namam for your quick answer. However, it isn't working yet. It seems that "server" at upstream directive does not allow slash, like this: server 10.111.111.5/owncloud;

If i used it, i obtained nginx: [emerg] invalid host in upstream "10.111.111.5/owncloud" in /etc/nginx/nginx.conf:43

I started with the first upstream bugtracker, only, and nginx.conf like this:

    upstream bugtracker {
        server 10.111.111.12;
    }

    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  localhost;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
    }

    location /mstic{
        proxy_pass http://bugtracker;
    }
        
        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

After that, when accesing to my Nginx Reverse proxy http://10.111.111.10/mstic/ i obtain the following: Not Found The requested URL /mstic/ was not found on this server. and no further details on error or access logs.

Thanks a lot in advance for any extra help you could bring me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM