Apache2 falsche Umleitung

ClocxHD

Lt. Junior Grade
Registriert
Aug. 2014
Beiträge
376
Hallo,

habe auf meinem Debian-Server Apache2 installiert.
Dort verwende ich 4 Virtual Hosts, die auch alle funktionieren.

Wenn ich z.B. domain1.de/ungültig eingebe, komme ich auf die von mir in der .htaccess eingestellte 404 Seite.
Das funktioniert bei allen vHosts/Domains.

Wenn ich jedoch z.B. ungültig.domain1.de eingebe, wird der Inhalt eines anderen vHosts angezeigt.
Das ist bei allen Domains so.

Woran liegt das?

LG,
ClocxHD
 
Das sind nun mal Subdomains und die werden geregelt verwalten. Wenn du immerhin auf nen Host weitergeleitet wirst, hast du schon mal nen Wildcard-DNS-Record gesetzt (*). Wenn der vHost dann nicht matcht, wird automatisch der erste vHost verwendet, der in der Config auftaucht. Ordne also so um, dass der erste vHost immer deine Seite ist, dann klappt das auch. Wenn du mit Configs arbeitest (sollte Debian ja sowieso machen), dann setz einfach ein 000 o.ä. vor den ersten vHost, hauptsache so, dass die Config ganz oben steht. Ggf. mal die httpd.conf nachprüfen, aber das sollte afaik nicht gemacht sein.
 
Habe jetzt einen vHost mit 000 im Namen.
Funktioniert trotzdem nicht. (Apache natürlich neu gestartet und vHost vorher aktiviert)
Unter Debian habe ich aber nur die apache2.conf
 
In /etc/apache2/sites-available solltest du eigentlich bereits den vordefinitierten vHost-Eintrag finden. Wo du dann weitere vHosts anlegst, musst du selbst wissen. Wahrscheinlich laden deine vHosts (wo auch immer die gesetzt sind), bevor die vHosts in obigem Pfad geladen werden.
 
Den vordefinierten Eintrag habe ich verändert und es hat nichts gebracht.
Dann habe ich den vordefinierten deaktiviert und einen neuen erstellt.
Meine vHosts sind in dem von dir genannten Pfad.
 
Gut, gehen wir mal Schritt für Schritt vor:

In der httpd.conf sind keine vHost-Einträge gesetzt, sondern diese werden ganz unten per Include sites-enabled/*.conf eingebunden?
Die apache2.conf/httpd.conf sollte eigentlich keinen vHost-Eintrag beherbergen. Ist dort ggf. der DocumentRoot-Pfad, ServerName, etc. gesetzt und zeigt auf den falschen vHost?
In /etc/apache2/sites-available sind also deine vier vHosts gesetzt und in je einer conf-Datei?
Alle Relevanten und Aktivierten sind wiederum in /etc/apache2/sites-enabled gelinkt?
Alle vHost-Einträge haben die korrekte ServerName-Direktive gesetzt?
Der standardmäßige vHost-Eintrag ist mit 000- o.ä. angeführt, sodass er als erstes im Verzeichnis auftaucht?

Ein vHost-Eintrag sollte außerdem wie folgt aussehen (ich füg einfach mal direkt das Template ein, das ich für die Erstellung mittels einem PowerShell-Script für vHosts nutze):
Code:
<VirtualHost *:80>
	ServerAdmin   ###SERVERADMIN###
	ServerName    ###HOSTNAME###
	ServerAlias   ###ALIASES###
	DocumentRoot  "D:/Entwicklung/PHP/###HOSTNAME###/www###DOCROOT###"
	ErrorLog      "D:/Entwicklung/PHP/###HOSTNAME###/logs/error.log"
	CustomLog     "D:/Entwicklung/PHP/###HOSTNAME###/logs/access.log" combined
	
	###PHP_INI###
	###PHP_BINARY###
	###VHOST_SETTINGS###

	<Directory "D:/Entwicklung/PHP/###HOSTNAME###/www">
		Require       all granted
		AllowOverride all
		Options       +ExecCGI +FollowSymLinks
		Order         allow,deny
		Allow from all
		
		###VHOST_SETTINGS_DIR###
	</Directory>
</VirtualHost>
Hier darauf achten wie gesagt, dass die ServerName-Direktive korrekt gesetzt ist und dass der Standard-vHost-Eintrag mit 000- beginnt.

Meine 000-localhost.conf als Beispiel:
Code:
<VirtualHost *:80>
	ServerAdmin   Dev
	ServerName    localhost
	ServerAlias   
	DocumentRoot  "D:/Entwicklung/PHP/localhost/www"
	ErrorLog      "D:/Entwicklung/PHP/localhost/logs/error.log"
	CustomLog     "D:/Entwicklung/PHP/localhost/logs/access.log" combined
	
		FcgidInitialEnv PHPRC "C:/x86/php/current/php.ini"
		<Files ~ "\.php$">
		AddHandler fcgid-script .php
		FcgidWrapper "C:/x86/php/current/php-cgi.exe" .php
	</Files>
	

	<Directory "D:/Entwicklung/PHP/localhost/www">
		Require       all granted
		AllowOverride all
		Options       +ExecCGI +FollowSymLinks
		Order         allow,deny
		Allow from all
		
		
	</Directory>
</VirtualHost>
Als ServerName natürlich entsprechend [subdomain.]domain.tld einsetzen anstatt hier localhost.
 
Gut, der Eintrag ist schon mal falsch. Lies dir ggf. mal die Doku dazu durch (dort ist auch das mit dem Standard-Host erklärt). Die vHosts, die du erstellst, laufen alle auf einer unterschiedlichen Domain. Du musst alle diese in den gleichen Pool werfen.

Mal als Auflistung meine vHosts von meinem Server:
Code:
000-domain.tld.conf
adm.domain.tld.conf
c.domain.tld.conf
cdn.domain.tld.conf
d.domain.tld.conf
gals.domain.tld.conf
ip.domain.tld.conf
ipv4.domain.tld.conf
ipv6.domain.tld.conf
mail.domain.tld.conf
p.domain.tld.conf
pma.domain.tld.conf
Die 000-domain.tld.conf:
Code:
<VirtualHost *:80>
	ServerAdmin   Admin
	ServerName    domain.tld
	ServerAlias   
	DocumentRoot  "C:/http/domain.tld/www"
	ErrorLog      "C:/http/domain.tld/logs/error.log"
	CustomLog     "C:/http/domain.tld/logs/access.log" combined
	
	FcgidInitialEnv PHPRC "C:/x86/php/current/php.ini"
	<Files ~ "\.php$">
    AddHandler fcgid-script .php
    FcgidWrapper "C:/x86/php/current/php-cgi.exe" .php
</Files>
	

	<Directory "C:/http/domain.tld/www">
		Require       all granted
		AllowOverride all
		Options       +ExecCGI +FollowSymLinks
		Order         allow,deny
		Allow from all
		
		
	</Directory>
</VirtualHost>

<VirtualHost *:443>
	ServerAdmin   Admin
	ServerName    domain.tld
	ServerAlias   
	DocumentRoot  "C:/http/domain.tld/www"
	ErrorLog      "C:/http/domain.tld/logs/error.log"
	CustomLog     "C:/http/domain.tld/logs/access.log" combined
	
	FcgidInitialEnv PHPRC "C:/x86/php/current/php.ini"
	<Files ~ "\.php$">
    AddHandler fcgid-script .php
    FcgidWrapper "C:/x86/php/current/php-cgi.exe" .php
</Files>
	

	SSLEngine 							on
	SSLCertificateFile 			"C:/http/.certificates/.domain.tld/.domain.tld.crt"
	SSLCertificateKeyFile 	"C:/http/.certificates/.domain.tld/.domain.tld.key"
	SSLCertificateChainFile	"C:/http/.certificates/.domain.tld/.domain.tld.crt"

	<Directory "C:/http/domain.tld/www">
		Require       all granted
		AllowOverride all
		Options       +ExecCGI +FollowSymLinks
		Order         allow,deny
		Allow from all
		
		
	</Directory>
</VirtualHost>
adm.domain.tld.conf:
Code:
<VirtualHost *:80>
	ServerAdmin   Admin
	ServerName    adm.domain.tld
	ServerAlias   
	DocumentRoot  "C:/http/adm.domain.tld/www"
	ErrorLog      "C:/http/adm.domain.tld/logs/error.log"
	CustomLog     "C:/http/adm.domain.tld/logs/access.log" combined
	
	FcgidInitialEnv PHPRC "C:/x86/php/current/php.ini"
	<Files ~ "\.php$">
    AddHandler fcgid-script .php
    FcgidWrapper "C:/x86/php/current/php-cgi.exe" .php
</Files>
	

	<Directory "C:/http/adm.domain.tld/www">
		Require       all granted
		AllowOverride all
		Options       +ExecCGI +FollowSymLinks
		Order         allow,deny
		Allow from all
		
		
	</Directory>
</VirtualHost>

<VirtualHost *:443>
	ServerAdmin   Admin
	ServerName    adm.domain.tld
	ServerAlias   
	DocumentRoot  "C:/http/adm.domain.tld/www"
	ErrorLog      "C:/http/adm.domain.tld/logs/error.log"
	CustomLog     "C:/http/adm.domain.tld/logs/access.log" combined
	
	FcgidInitialEnv PHPRC "C:/x86/php/current/php.ini"
	<Files ~ "\.php$">
    AddHandler fcgid-script .php
    FcgidWrapper "C:/x86/php/current/php-cgi.exe" .php
</Files>
	

	SSLEngine 							on
	SSLCertificateFile 			"C:/http/.certificates/.domain.tld/.domain.tld.crt"
	SSLCertificateKeyFile 	"C:/http/.certificates/.domain.tld/.domain.tld.key"
	SSLCertificateChainFile	"C:/http/.certificates/.domain.tld/.domain.tld.crt"

	<Directory "C:/http/adm.domain.tld/www">
		Require       all granted
		AllowOverride all
		Options       +ExecCGI +FollowSymLinks
		Order         allow,deny
		Allow from all
		
		
	</Directory>
</VirtualHost>
c.domain.tld.conf:
Code:
<VirtualHost *:80>
	ServerAdmin   Admin
	ServerName    c.domain.tld
	ServerAlias   
	DocumentRoot  "C:/http/c.domain.tld/www"
	ErrorLog      "C:/http/c.domain.tld/logs/error.log"
	CustomLog     "C:/http/c.domain.tld/logs/access.log" combined
	
	FcgidInitialEnv PHPRC "C:/x86/php/current/php.ini"
	<Files ~ "\.php$">
    AddHandler fcgid-script .php
    FcgidWrapper "C:/x86/php/current/php-cgi.exe" .php
</Files>
	

	<Directory "C:/http/c.domain.tld/www">
		Require       all granted
		AllowOverride all
		Options       +ExecCGI +FollowSymLinks
		Order         allow,deny
		Allow from all
		
		
	</Directory>
</VirtualHost>

<VirtualHost *:443>
	ServerAdmin   Admin
	ServerName    c.domain.tld
	ServerAlias   
	DocumentRoot  "C:/http/c.domain.tld/www"
	ErrorLog      "C:/http/c.domain.tld/logs/error.log"
	CustomLog     "C:/http/c.domain.tld/logs/access.log" combined
	
	FcgidInitialEnv PHPRC "C:/x86/php/current/php.ini"
	<Files ~ "\.php$">
    AddHandler fcgid-script .php
    FcgidWrapper "C:/x86/php/current/php-cgi.exe" .php
</Files>
	

	SSLEngine 							on
	SSLCertificateFile 			"C:/http/.certificates/.domain.tld/.domain.tld.crt"
	SSLCertificateKeyFile 	"C:/http/.certificates/.domain.tld/.domain.tld.key"
	SSLCertificateChainFile	"C:/http/.certificates/.domain.tld/.domain.tld.crt"

	<Directory "C:/http/c.domain.tld/www">
		Require       all granted
		AllowOverride all
		Options       +ExecCGI +FollowSymLinks
		Order         allow,deny
		Allow from all
		
		
	</Directory>
</VirtualHost>
usw. Die vHosts unterscheiden sich nur zwischen den Einträgen in der ServerName-Direktive (und im Pfad natürlich). Name Based Virtual Hosts (ergo die NameVirtualHost-Direktive) ist in Apache 2.4 auch als deprecated markiert. Das kannst du eigentlich auch gleich weg lassen. Ggf. solltest du auch mal nachdenken, ob du nicht einfach *:80 als Parameter im VirtualHost-Eintrag mitgibst, hast ja eh nur einen Apache laufen oder? Die (Sub-)Domain-Unterscheidung läuft ja sowieso über ServerName ab.
 
Zurück
Oben