Redirect request from domain to ip

Alles, was den Apache betrifft, kann hier besprochen werden.

Redirect request from domain to ip

Postby auka » 04. January 2023 12:35

Hello,

I have a web deployed on an Apache server which need to call to a back-end service located in the same server, listening another port. I'm not in charge of the back-end side, which is implemented on Django and is not configured to listen requests to the domain, only listens the ip. Unfortunately, I can't change the configuration of the back-end.

We have installed an SSL certificate and now we have problems, because the web browser doesn't allow to connect to the ip. So I would like to create a temporary solution until the person in charge of Django fix the problem.

I would like to redirect requests to the domain to the ip using a reverse proxy. I don't know how to do it with a .htaccess file so I would thank some support from you.

For example, I would like that any request done to mydomainserver.com/data/user/1 would be internally redirect to 123.123.2.3/data/user/1

Is this possible?

Thanks!
auka
 
Posts: 3
Joined: 04. January 2023 12:25
XAMPP version: 8.1.12
Operating System: Manjaro

Re: Redirect request from domain to ip

Postby Altrea » 04. January 2023 13:55

Hi,

Apache does have a really good documentation: https://httpd.apache.org/docs/2.4/howto ... proxy.html
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: Redirect request from domain to ip

Postby Nobbie » 05. January 2023 11:15

auka wrote:and is not configured to listen requests to the domain, only listens the ip.


What??? That is weird. A server NEVER(!) "listens" to domain names, they ALWAYS only listen to the ip. You only need to assign a domain name to the IP and need an DNS Server which supports this domain name (this can be the hosts file in the easiest case) and request that domain in a browser. The browser ALWAYS will send an DNS request and will get the corresponding IP, finally the browser sends a TCP/IP request to the IP (and not to the domain). You simply can add a line in your hosts file (in Linux it is /etc/hosts) like this:

123.123.2.3 djangoserver.local

Then simply request data from your Django like this in your local Browser: https://djangoserver.local/file.hml
If Django listens to a different port than 80 (http) or 443 (https), you simply apply the Port in the URL like: https://djangoserver.local:1234/file.hml, where 1234 is the port number.

The Browser will open a request on 123.123.2.3 and send a HTTP request like "GET /file.html host=djangoserver.local" but the request is sent to the IP 123.123.2.3 and NOT to a domain name. You have a wrong understanding about domain names and IPs.

auka wrote:I don't know how to do it with a .htaccess file


You cannot use ProxyPass in a .htaccess, only Context "server, virtualhost, directory" is applicable (only in Apache configuration files).
Nobbie
 
Posts: 13165
Joined: 09. March 2008 13:04

Re: Redirect request from domain to ip

Postby auka » 09. January 2023 16:27

Nobbie wrote:
auka wrote:and is not configured to listen requests to the domain, only listens the ip.


What??? That is weird. A server NEVER(!) "listens" to domain names, they ALWAYS only listen to the ip. You only need to assign a domain name to the IP and need an DNS Server which supports this domain name (this can be the hosts file in the easiest case) and request that domain in a browser. The browser ALWAYS will send an DNS request and will get the corresponding IP, finally the browser sends a TCP/IP request to the IP (and not to the domain). You simply can add a line in your hosts file (in Linux it is /etc/hosts) like this:

123.123.2.3 djangoserver.local

Then simply request data from your Django like this in your local Browser: https://djangoserver.local/file.hml
If Django listens to a different port than 80 (http) or 443 (https), you simply apply the Port in the URL like: https://djangoserver.local:1234/file.hml, where 1234 is the port number.

The Browser will open a request on 123.123.2.3 and send a HTTP request like "GET /file.html host=djangoserver.local" but the request is sent to the IP 123.123.2.3 and NOT to a domain name. You have a wrong understanding about domain names and IPs.

auka wrote:I don't know how to do it with a .htaccess file


You cannot use ProxyPass in a .htaccess, only Context "server, virtualhost, directory" is applicable (only in Apache configuration files).


Hello Nobbie,

Thanks for your reply. The problem here is that Django is configured to serve requests to the ip, not de domain. Maybe "listen" was not the correct word to describe the situation. But the file config ALLOWED_HOSTS only contains the ip so that any request to the domain is ignored, and I don't have file permissions to change that.

But I've solved it using the ProxPass property in the virtual host server configuration.

Thanks!
auka
 
Posts: 3
Joined: 04. January 2023 12:25
XAMPP version: 8.1.12
Operating System: Manjaro

Re: Redirect request from domain to ip

Postby auka » 09. January 2023 16:29

Altrea wrote:Hi,

Apache does have a really good documentation: https://httpd.apache.org/docs/2.4/howto/reverse_proxy.html


Thanks! I didn't imagine that using a reverse proxy in apache was too simple
auka
 
Posts: 3
Joined: 04. January 2023 12:25
XAMPP version: 8.1.12
Operating System: Manjaro


Return to Apache

Who is online

Users browsing this forum: No registered users and 219 guests