【问题标题】:Can't bind virtual host to different port with httpd (CentOS)无法使用 httpd (CentOS) 将虚拟主机绑定到不同的端口
【发布时间】:2016-08-05 06:04:56
【问题描述】:

我有一个带有 CentOS 和 Apache 的 VDS。我正在使用基于虚拟的主机,所以我有域“my.domain”和几个子域,如“sub1.my.domain”、“sub2.my.domain”等。它们每个都有自己的配置文件在 /etc/ httpd/conf/vhosts/.

我需要将所有连接从 sub1.my.domain:8080 重定向到 another.web.site:8080。所以我在 sub1.my.domain 的根目录的 .htaccess 文件中添加了这些行:

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

但它不起作用,因为网络服务器只监听端口 80。所以我确实这样修改了 /etc/httpd/httpd.conf:

Listen 80
Listen 8080

并且修改了 sub1.my.domain 的 vhost 文件。而不是...

<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>

...现在内容

<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>

official documentation 中所述,我添加了新端口以在 httpd 配置中侦听并设置新端口以在域的虚拟主机配置中解析。但是当我试图打开 sub1.my.domain:8080 时,我收到一个错误 - 浏览器无法解析该地址。我什至通过 iptables 转发 8080 端口,重新启动整个服务器但没有任何帮助。

我做错了什么?

【问题讨论】:

    标签: apache .htaccess redirect httpd.conf vhosts


    【解决方案1】:

    花了一整天的时间来了解 fail2ban 阻止了与 8080 的所有连接。我已经通过 iptables 向 fail2ban 表添加了规则,一切都像一个魅力。

    【讨论】:

      猜你喜欢
      • 2018-09-20
      • 2014-04-25
      • 2011-08-29
      • 2013-04-26
      • 2014-05-15
      • 2021-05-03
      • 2011-10-11
      • 2012-03-27
      • 2016-04-08
      相关资源
      最近更新 更多