0

I seek some wisdom, so please help... I have one VM acting as router/web server/dnsmasq server on IP: 192.168.100.1. And I have other machine acting as client.

Server has IPTables rule to redirect any traffic coming from port 80 to port 8081.

iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 80 -j REDIRECT --to-port 8081

I also created name-based virtual host on server listening on port 8081 with following configuration.

<VirtualHost *:8081>
RewriteEngine On
RewriteRulle .* http://cpt.haustor.org [R,L]
ServerName haustor.org
ServerAlias cpt.haustor.org
DocumentRoot /var/opt/mypage
<Directory /var/opt/mypage>
    DirectoryIndex index.html
    Require all granted
    Options Indexes FollowSymLinks Includes
</Director>

Domain haustor.org and sub-domain cpt.haustor.org is hosted locally on server machine and is present in /etc/hosts file:

192.168.100.1 cpt.haustor.org haustor.org

Client is able to resolve IP of web server (192.168.100.1): Dig issued on client:

root@captivo:~# dig cpt.haustor.org

; <<>> DiG 9.9.5-9+deb8u2-Debian <<>> cpt.haustor.org
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 41972
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096 
;; QUESTION SECTION:
;cpt.haustor.org.               IN      A

;; ANSWER SECTION:
cpt.haustor.org.        0       IN      A       192.168.100.1

;; Query time: 1 msec
;; SERVER: 192.168.100.1#53(192.168.100.1)
;; WHEN: Sun Aug 16 22:28:43 CEST 2015
;; MSG SIZE  rcvd: 60

Everything seems to be fine from this perspective, but what happens when I try to access any URL from Konqueror is that I get error page which states that there is cyclic link in place. An honestly I'm out of ideas how to resolve this. Currently I'm using Debian 8, Apache 2.4.10 and dnsmasq 2.72.

Plesae help me resolve this problem.

P.S. The same config worked on CentOS 6 with no problems.

BR, Neven

UPDATE:

Looking at log what I see is that page is really invoked multiple times at same time:

root@captivo:~# cat /var/log/apache2/captivo-custom.log 
192.168.100.115 - - [16/Aug/2015:22:49:19 +0200] "GET / HTTP/1.1" 302 531
192.168.100.115 - - [16/Aug/2015:22:49:19 +0200] "GET / HTTP/1.1" 302 534
192.168.100.115 - - [16/Aug/2015:22:49:19 +0200] "GET / HTTP/1.1" 302 533
192.168.100.115 - - [16/Aug/2015:22:49:19 +0200] "GET / HTTP/1.1" 302 533
192.168.100.115 - - [16/Aug/2015:22:49:19 +0200] "GET / HTTP/1.1" 302 533
192.168.100.115 - - [16/Aug/2015:22:49:19 +0200] "GET / HTTP/1.1" 302 533
192.168.100.115 - - [16/Aug/2015:22:49:19 +0200] "GET / HTTP/1.1" 302 533
root@captivo:~# 
1

Obviously RewriteRule matching anything causes the loop. Disable it.

If you want to simply redirect http://haustor.org/ to http://cpt.haustor.org/, declare <VirtualHost> for each virtual host.

<VirtualHost *:8081>
ServerName haustor.org
Redirect / http://cpt.haustor.org/
</VirtualHost>

<VirtualHost *:8081>
ServerName cpt.haustor.org
DocumentRoot /var/opt/mypage
<Directory /var/opt/mypage>
    DirectoryIndex index.html
    Require all granted
    Options Indexes FollowSymLinks Includes
</Directory>
</VirtualHost>
  • Hi yaegasi, thank you for answer, however what I want to achieve is that ANY domain entered is redirected to cpt.haustor.org. So, if somebody enters www.xyz.com, that request is redirected to cpt.haustor.org. I would say that with your solution only when haustor.org is requested, that request will be sent towards cpt.haustor.org. Am I right? – Neven Aug 17 '15 at 7:33
  • This configuration with 2 <VirtualHost> acts just as you want. From Apache doc: If no matching ServerName or ServerAlias is found in the set of virtual hosts containing the most specific matching IP address and port combination, then the first listed virtual host that matches that will be used. – yaegashi Aug 17 '15 at 7:47
  • Thank you, I'll give it a try in the evening and try to make it work and mark your answer as correct correspondingly or come back with additional question. :) – Neven Aug 17 '15 at 8:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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