2

Say my client (current device) wants to connect to a URL, say foo.bar.com/spam/eggs/123, how do I serve or redirect to another specified URL, say 127.0.0.1:8080, and prevent the client from reaching foo.bar.com/spam/eggs/123?

What software can I use?

2
  • What operating system are you using ? please provide more information
    – Saxtheowl
    Apr 3 at 8:26
  • 1
    I am using linux @Saxtheowl
    – Anm
    Apr 3 at 13:05

2 Answers 2

4

If I understand your setup, you have some external domain, example.com, controlled by a 3rd party, with a website running on it, controlled by someone else. You want to allow access to that site generally, but block certain URLs.

There are a few solutions to this; they all boil down to some sort of proxy server. You would proxy web traffic via this proxy server and have a block/redirect list configured in it, which would deal with predefined exceptions.

One free solution is squid caching proxy, which does have redirectors support (here are details in the documentation - https://wiki.squid-cache.org/Features/Redirectors). Do note though that it's very much not trivial to set this up correctly and maintain it. No disrespect, but based on the fact that you had to ask this question, I suspect you may struggle to do this successfully.

1

You should use a reverse proxy like Nginx first install it sudo apt-get install nginx then go to the configuration file at /etc/nginx/sites-available/foo.bar.conf and put this inside:

server {
    listen 80;
    server_name foo.bar.com;

    location /spam/eggs/123 {
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

then enable it with ln -s /etc/nginx/sites-available/foo.bar.conf /etc/nginx/sites-enabled/

With this configuration, when a client tries to connect to foo.bar.com/spam/eggs/123, Nginx will redirect the request to http://127.0.0.1:8080

then reload Nginx sudo systemctl reload nginx

3
  • it is always better not to modify existing distribution-installed files it possible, but to add your own alongside into the configuration drop directory (so a package update won't disturb it, for example). In this case, better put this content into /etc/nginx/sites-avaliable/foo.bar.conf and enable it with ln -s /etc/nginx/sites-available/foo.bar.conf /etc/nginx/sites-enabled/. Also restart is not required, reload is enough. Apr 3 at 13:30
  • 1
    This did not work for me, isnt nginx a reverse proxy? foo.bar.com is not owned by me but I would like to redirect a specific location on it, and allow the rest
    – Anm
    Apr 3 at 15:09
  • 2
    I downvoted this because it doesn't answer the question and doesn't work.
    – user253751
    Apr 3 at 17:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .