Reputation: 13
It's just my project. It's growing up and I want to add a new server as a sub-directory on the same domain. Is it possible to make sub-directory like:
example.com 127.0.0.1
example.com/project1/ 127.0.0.2
example.com/project2/ 127.0.0.3
How I config a DNS or Apache to make it work?
Upvotes: 0
Views: 175
Reputation: 3526
Sounds like you want to implement a proxy which can be done with mod_proxy. I assume the sites are already running on 127.0.0.2
and 127.0.0.3
and the public frontend is on 127.0.0.1
You will need to edit the configuration files on 127.0.0.1
and either in the main configuration (for a single site) or virtual host block for a virtual host, add the ProxyPass configuration:
ProxyPass /project1/ http://127.0.0.2/
ProxyPass /project2/ http://127.0.0.3/
This will send all requests from /project1/
to http://127.0.0.2/
, if you want to keep this server hidden, or it's not accessible by the public such as an internal network address you will need to set up a reverse proxy so the results are fed back to users via your public front end, so you will need to add ProxyPassReverse configuration:
ProxyPassReverse /project1/ http://127.0.0.2/
ProxyPassReverse /project2/ http://127.0.0.3/
Further to this, you will need to enable the proxy modules in your configuration files as well, these are what I have enabled for a basic reverse proxy
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
There are some other modules that could be important depending on your situation
mod_proxy_connect This handles the CONNECT function if connecting to https:// servers
mod_proxy_ftp This handles connections to FTP servers
mod_proxy_ajp This handles connections to tomcat/AJP servers
mod_headers This can modify response and request headers
mod_deflate This negotiates compression with backends
mod_proxy_html This is a 3rd party module which will rewrite HTML links to the proxy address space
Upvotes: 2