【发布时间】: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