简体   繁体   中英

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?

一整天都在了解fail2ban会阻止所有与8080的连接。我已经通过iptables将规则添加到了fail2ban表中,并且一切正常。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM