通配符子域上的dynamic虚拟主机隐藏在CNAME后面

介绍

我有一个社区,每个用户都可以在我的项目上有自己的子域名,例如username1.mydomain.com

在PHP中,我使用variablesHTTP_HOST来确定用户名(username1)。

任务

让用户通过CNAMElogging将自己的域路由到他的子域。 www.usersdomain.com应链接到username1.mydomain.com。

问题

添加CNAMElogging(www.usersdomain.com)后,HTTP_HOSTvariables应该返回username1.mydomain.com而不是www.usersdomain.com。

我该如何解决这个问题? 希望有人能帮助我,请。

当前虚拟主机设置

<VirtualHost *:80> DocumentRoot /home/webapps/egoapp/current/public <DirectoryMatch /\.git/|/\.svn/ > Deny from all </DirectoryMatch> <Directory "/home/webapps/egoapp/current"> Options FollowSymLinks AllowOverride All Order allow,deny Allow from all </Directory> RewriteEngine On # Enable status page for monitoring purposes RewriteCond %{REMOTE_ADDR} ^(127.0.0.1) RewriteRule ^(/server-status) $1 [H=server-status,L] # Redirects to a maintenance page if the specified file below exists # ...but it still allows images to be served RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f RewriteCond %{SCRIPT_FILENAME} !/system/maintenance.html RewriteCond %{SCRIPT_FILENAME} !^(.+).(gif|png|jpg|css|js|swf)$ RewriteRule ^.*$ /system/maintenance.html [L] # <CUSTOM RULES BEFORE FORWARDING END> # Proxy the rest to the load balancer RewriteRule ^/(.*)$ http://127.0.0.1:85%{REQUEST_URI} [P,QSA,L] # Setup the logs in the appropriate directory CustomLog /var/log/httpd/access_log combined #ErrorLog /var/log/httpd/error_log #Remote logging -- handle by syslog ErrorLog "|logger -p local3.info -t httperror" CustomLog "|logger -p local3.info -t http" combined LogLevel warn # Deflate AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript BrowserMatch ^Mozilla/4 gzip-only-text/html BrowserMatch ^Mozilla/4.0[678] no-gzip BrowserMatch bMSIE !no-gzip !gzip-only-text/html SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0 </VirtualHost> 

解决这个问题的想法

我想我必须编辑/etc/resolv.conf,但我不知道如何;)播放一下后,我可以将Servername更改为127.0.0.1或“undefinded domain”,而不是username1.mydomain.com

当前Resov.conf

searcheu-west-1.compute.internal
nameserver xxx.xxx.xxx.xxx

HTTP_HOSTvariables是根据客户端发送给您的虚拟主机的实际URI请求创build的。 这实际上与你的DNS没有任何关系,只是一个string,所以编辑你的resolv.conf将无济于事。 在客户端连接到服务器并提供HTTP_HOST的时候,它已经完成了parsingDNS和确定哪个IP地址要发送请求到这个URI的工作。

我认为你最简单的解决scheme是将www.usersdomain.com和username1之间的关联存储在某种数据库中,并将HTTP_HOSTvariables编译到数据库以确定返回哪个用户的站点。

您唯一的select是为每个域手动configuration新的虚拟主机。 这可能非常耗时且容易出错,我会使用数据库驱动的方法,将其集成到您的网站中,并且相对自动化。