Reputation: 154
How do you create a reverse proxy? I want to create a site that uses a table of urls with identifiers for each url. If you go to http://site.com/id where id is an identifier for a url it would act as a reverse proxy and retrieve the content from the url.
I looked into using apache reverse proxy features but there doesn't seem to be a way to scale it without restarting the server every time you need to reverse proxy a new site.
Upvotes: 0
Views: 888
Reputation: 17771
Using Apache to create a reverse proxy using mod_rewrite in the main httpd.conf
(under the relevant if applicable):
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com [NC]
RewriteCond %{REQUEST_URI} ^/id$
RewriteRule ^.*$ http://www.proxydomain.com/newUrl [P,L]
First line checks for www.mydomain.com
or mydomain.com
Second line identifies the /id
portion of the URL
If the first two conditions are met the request is made by Apache to www.proxydomain.com/newUrl
and then returned to the client.
You don't have to fully restart Apache to make these changes. Do a config check and then restart gracefully, which doesn't take the server offline and reloads configuration:
/etc/init.d/httpd configtest && /etc/init.d/httpd graceful
Alternatively this code can go into an .htaccess
file, which is less preferable.
Upvotes: 1