
導入
私はコミュニティを持っており、すべてのユーザーはプロジェクトで独自のサブドメインを持つことができます(例:username1.mydomain.com)。
PHP では、変数 HTTP_HOST を使用してユーザー名 (username1) を決定します。
タスク
ユーザーが CNAME レコードを使用して自身のドメインをサブドメインにルーティングできるようにします。www.usersdomain.com は username1.mydomain.com にリンクする必要があります。
問題
CNAME レコード (www.usersdomain.com) を追加すると、HTTP_HOST 変数は www.usersdomain.com ではなく username1.mydomain.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 を編集する必要があると思いますが、方法がわかりません ;) 少し試した後、サーバー名を 127.0.0.1 または「未定義のドメイン」に変更することはできますが、username1.mydomain.com には変更できません。
現在の Resov.conf
eu-west-1.compute.internal
ネームサーバー xxx.xxx.xxx.xxxを検索
答え1
HTTP_HOST 変数は、クライアントが仮想ホストに送信した実際の URI 要求から作成されます。これは実際には DNS とは何の関係もなく、単なる文字列なので、resolv.conf を編集しても役に立ちません。クライアントがサーバーに接続して HTTP_HOST を提供する時点で、DNS を解決し、その URI の要求を送信する IP アドレスを決定する作業はすでに完了しています。
最も簡単な解決策は、www.usersdomain.com と username1 の関連付けを何らかのデータベースに保存し、HTTP_HOST 変数をデータベースと比較して、どのユーザーのサイトを返すかを決定することだと思います。
唯一の他のオプションは、これらのドメインごとに新しい仮想ホストを手動で構成することです。これは時間がかかり、エラーが発生しやすいため、サイトに統合でき、比較的自動化できるデータベース駆動型の方法をお勧めします。