0

I currently have a DigitalOcean Ubuntu 16.04x64 server with Linux Containers to house multiple sites. One of the containers has HAProxy installed and routes incoming traffic to their appropriate containers. Each container has a unique IP Address given to it upon creation.

I ran the following command to create a rule to the iptables nat table:

sudo iptables -t nat -I PREROUTING -i eth0 -p TCP -d your_server_ip/32 --dport 80 -j DNAT --to-destination your_haproxy_ip:80

This works correctly and any domain I have pointed to the server gets redirected to the container its supposed to go to.

I am currently migrating sites from another server and still need the domains pointed there until I have tested the sites on the new server. Also, for future development I would like to access the containers without having a domain name pointed to it yet.

So my question is, how can I edit the above command to create a rule that will allow for sub directories? For example: 159.203.86.144/test or 159.203.86.144/10.23.98.211

2 Answers2

1

Agree with Michael Hampton, if you want to do it, you should use reverse proxy like nginx, it would be better solution. You could read about it in this article.

Alexander Tolkachev
  • 4,608
  • 3
  • 14
  • 23
  • Actually I just tested and figured out that it already is working and pointing to the correct container. The 404 Not Found error is coming from the nginx server within the container. I should be able to get the functionality I need now by setting the directory url within the container correctly. Thanks for the link to the article though, I'm sure it will still be helpful. – natmed91 Jan 12 '18 at 20:39
0

Ok so it turns out that the original rule that was made could already handle the sub directory path that I needed to reach the container.

http://server_ip/linux_container_ip

I added this configuration to the frontend of /etc/haproxy/haproxy.conf

acl host_test url_beg -i /linux_container_ip

And then within the Linux Container, added an alias to /etc/nginx/sites-available/default

location /linux_container_ip {
alias /path/to/root/production/folder/here;
}