
소개
저는 커뮤니티가 있고 모든 사용자는 내 프로젝트에 자체 하위 도메인(예: 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 또는 "확인되지 않은 도메인"으로 변경할 수 있지만 사용자 이름1.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 변수를 데이터베이스에 비교하여 반환할 사용자 사이트를 결정하는 것입니다.
유일한 다른 옵션은 이러한 각 도메인에 대해 새 가상 호스트를 수동으로 구성하는 것입니다. 이는 시간이 많이 걸리고 오류가 발생하기 쉬울 수 있습니다. 저는 귀하의 사이트에 통합될 수 있고 상대적으로 자동화될 수 있는 데이터베이스 기반 방법을 사용하겠습니다.