Venique
Venique

Reputation: 11

Can't bind virtual host to different port with httpd (CentOS)

I have a VDS with CentOS and Apache. I'm using virtual-based hosts so I have domain 'my.domain' and few subdomains like 'sub1.my.domain', 'sub2.my.domain' etc. Each of them have it own config file in /etc/httpd/conf/vhosts/.

I need to redirect all connections from sub1.my.domain:8080 to another.web.site:8080. So I've added this lines in .htaccess file at sub1.my.domain's root directory:

RewriteEngine On 
RewriteCond %{SERVER_PORT} 8080
RewriteCond %{REQUEST_URI} ^/
RewriteRule (.*) http://another.web.site:8080

But it wouldn't work because web-server listen only to port 80. So I did modified /etc/httpd/httpd.conf this way:

Listen 80
Listen 8080

And did modified sub1.my.domain's vhost file. Instead of...

<VirtualHost myserverip:80>
    ServerName sub1.my.domain
    AddDefaultCharset off
    AssignUserID www-root www-root
    DirectoryIndex index.html
    DocumentRoot /var/www/www-root/data/www/sub1.my.domain
...
</VirtualHost>

...it now contents

<VirtualHost myserverip:8080>
    ServerName sub1.my.domain
    AddDefaultCharset off
    AssignUserID www-root www-root
    DirectoryIndex index.html
    DocumentRoot /var/www/www-root/data/www/sub1.my.domain
...
</VirtualHost>

So as described in official documentation I've added new port to listen in httpd configuration and setup new port to resolve in domain's virtual host configuration. But when I'm trying to open sub1.my.domain:8080 I get an error - browser can't resolve that address. I've even forward 8080 port through iptables, reboot whole server but nothing helped.

What I did wrong?

Upvotes: 0

Views: 772

Answers (1)

Venique
Venique

Reputation: 11

Whole day spent to understand that fail2ban blocks all connections to 8080. I've added rule to fail2ban table through iptables and everything worked like a charm.

Upvotes: 0

Related Questions