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: or

closed as unclear what you're asking by kasperd, mdpc, MadHatter, Andrew Schulman, Jenny D Jan 17 '18 at 11:41

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 4
    You don't. Firewalls don't operate like that. – Michael Hampton Jan 12 '18 at 19:56

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.

  • 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

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.


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;

Not the answer you're looking for? Browse other questions tagged or ask your own question.