Zum Inhalt springen

Virtuellen Host einrichten (Ubuntu): Unterschied zwischen den Versionen

Aus Computech CMS Wiki
Simon Zeberli (Diskussion | Beiträge)
Die Seite wurde neu angelegt: „zum Verzeichnis gehen. cd /etc/apache2/sites-available Eine Datei erstellen nano example.conf <syntaxhighlight lang="shell"> NameVirtualHost *:80 <VirtualHo…“
 
 
(17 dazwischenliegende Versionen von 2 Benutzern werden nicht angezeigt)
Zeile 1: Zeile 1:
==Virtuellen Host erstellen==
zum Verzeichnis gehen.
zum Verzeichnis gehen.
  cd /etc/apache2/sites-available
  cd /etc/apache2/sites-available
Eine Datei erstellen  
Eine Datei erstellen  
  nano example.conf
  sudo nano example.conf
<syntaxhighlight lang="shell">
 
<syntaxhighlight lang="apache">
#Drupal installation
NameVirtualHost *:80
NameVirtualHost *:80
<VirtualHost  *:80>
<VirtualHost *:80>
  ServerAdmin webmaster@merks.li
  DocumentRoot /var/www/example
  DocumentRoot /var/www/html/merks.li
  ServerName example.dan
  ServerName merks.li
        <Directory "/usr/lib/cgi-bin">
  ServerAlias *.merks.li
                Require all granted
        </Directory>
    <FilesMatch ".php$">
        SetHandler "proxy:unix:/var/run/php/php7.4-fpm.sock|fcgi://localhost/"
      </FilesMatch>
<Directory "/var/www/example">
    AllowOverride All
    Require all granted
    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</Directory>
    ErrorLog ${APACHE_LOG_DIR}/error_drupal.log
    CustomLog ${APACHE_LOG_DIR}/access_drupal.log combined
</VirtualHost>
</syntaxhighlight>
 
alternativ: vorhandene .conf-Datei kopieren und anpassen
<syntaxhighlight lang="bash">
sudo sh -c 'cat VORLAGE.conf | sed 's/SUCHEN/ERSETZEN/g' > NEUEDOMAIN.conf'
</syntaxhighlight>
 
Seite Aktivieren mit folgendem Befehl.
sudo a2ensite example.conf
 
Apache neu starten
sudo service apache2 reload
 
==Virtuellen Host Löschen==
sudo a2dissite example.conf
 
=Virtuellen Host Alternative=
 
<syntaxhighlight lang="apache">
#Drupal installation
NameVirtualHost *:80
  <VirtualHost *:80>
  DocumentRoot /var/www/example
  ServerName example.ch
  ServerAlias *.example.ch
<Directory "/var/www/html/example">
    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</Directory>
</VirtualHost>
</syntaxhighlight>
* [[LE SSL-Zertifikat erstellen]]
==Weiterleitung ==
<syntaxhighlight lang="apache">
<VirtualHost *:80>
    ServerName SOURCE.ch
    ServerAlias *.SOURCE.ch
    RedirectMatch 301 ^/(.*)$ https://www.TARGET.ch/$1
</VirtualHost>
</VirtualHost>
</syntaxhighlight>
</syntaxhighlight>

Aktuelle Version vom 13. April 2022, 12:24 Uhr

Virtuellen Host erstellen

zum Verzeichnis gehen.

cd /etc/apache2/sites-available

Eine Datei erstellen

sudo nano example.conf
#Drupal installation
NameVirtualHost *:80
 <VirtualHost *:80>
   DocumentRoot /var/www/example
   ServerName example.dan
        <Directory "/usr/lib/cgi-bin">
                Require all granted
        </Directory>
     <FilesMatch ".php$">
         SetHandler "proxy:unix:/var/run/php/php7.4-fpm.sock|fcgi://localhost/"
      </FilesMatch>
 <Directory "/var/www/example">
    AllowOverride All
    Require all granted
    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
 </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error_drupal.log
    CustomLog ${APACHE_LOG_DIR}/access_drupal.log combined
 </VirtualHost>

alternativ: vorhandene .conf-Datei kopieren und anpassen

sudo sh -c 'cat VORLAGE.conf | sed 's/SUCHEN/ERSETZEN/g' > NEUEDOMAIN.conf'

Seite Aktivieren mit folgendem Befehl.

sudo a2ensite example.conf

Apache neu starten

sudo service apache2 reload

Virtuellen Host Löschen

sudo a2dissite example.conf

Virtuellen Host Alternative

#Drupal installation
NameVirtualHost *:80
 <VirtualHost *:80>
   DocumentRoot /var/www/example
   ServerName example.ch
   ServerAlias *.example.ch
 <Directory "/var/www/html/example">
    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
 </Directory>
 </VirtualHost>

Weiterleitung

<VirtualHost *:80>
    ServerName SOURCE.ch
    ServerAlias *.SOURCE.ch
    RedirectMatch 301 ^/(.*)$ https://www.TARGET.ch/$1
</VirtualHost>