{{tag>portail}}
====== Cohabitation apache2 et nginx ======
===== Essai d'installation de LAMP alors que nginx est en fonction =====
...@...:~ $ sudo apt install {apache2,php,php-{pear,mysql},libapache2-mod-php,mariadb-server}
...
Les paquets supplémentaires suivants seront installés :
libapache2-mod-php7.4
Les NOUVEAUX paquets suivants seront installés :
libapache2-mod-php libapache2-mod-php7.4 php-pear
...
Souhaitez-vous continuer ? [O/n]
...
No module matches
apache2_switch_mpm: MPM prefork not found
libapache2-mod-php7.4: Could not switch to prefork MPM, not enabling PHP 7.4
...
...@...:~$ tree /etc/apache2/sites-available/
/etc/apache2/sites-available/
├── 000-default.conf
└── 000-default.conf.original
0 directories, 2 files
nicolas@chateau:~$ tree /etc/apache2/
/etc/apache2/
├── conf-available
├── conf-enabled
├── mods-available
├── mods-enabled
├── sites-available
│ ├── 000-default.conf
│ └── 000-default.conf.original
└── sites-enabled
6 directories, 2 files
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
===== J'ai actuellement un vps en debian 8 qui a un serveur nginx avec un gitlab. =====
J'ai actuellement un vps en debian 8 qui a un serveur nginx avec un gitlab.
Je souhaiterais mettre en place un serveur apache2 avec un site web pour le faire fonctionner en parallèle avec nginx, par exemple :
* **gitlab.monurl.fr** pour gitlab sous nginx
* et **web.monurl.fr** pour mon site web sous apache
Cela devrait être possible si on passe par apache pour rediriger les requêtes qui sont pour gitlab.monurl.fr.
^ serveur ^ nginx ^ apache ^
^ site | gitlab.monurl.fr | web.monurl.fr |
^ DNS -> IP | 80.20.30.4 | 80.20.30.4 |
^ Port d'écoute | 8080 (ou 8008) | 80 |
| | | virtualhost |
Hypothèses:
- Il y a une entrée DNS **gitlab.monurl.fr** (ex: gitlab.monurl.fr -> 80.20.30.4)
- Il y a une entrée DNS **web.monurl.fr** (ex: web.monurl.fr -> 80.20.30.4)
- Le serveur NGinx écoute sur le port 8080
- Le serveur Apache écoute sur le port 80
- Le site web.monurl.fr est configuré dans un virtualhost.
Sur la configuration apache, il faut activer le module rewrite.
Ensuite, créez une redirection pour les requêtes http qui sont pour **gitlab.monurl.fr**, vers l'url suivante : **http://gitlab.monurl.fr:8080/**
Exemple de configuration pour le virtualhost **web.monurl.fr**:
ServerName web.monurl.fr
ServerAlias web.monurl.fr gitlab.monurl.fr
# -------------------------------------------
RewriteEngine On
RewriteCond %{HTTP_HOST} !^gitlab\.monurl\.fr [NC]
RewriteRule ^/(.*) http://gitlab.monurl.fr:8080/$1 [L,R]
#---------------
# Ta configuration pour ton site apache web.monurl.fr
#---------------
ps: Je n'ai pas testé ma proposition. Ce n'est qu'une idée de travail.
===== Voir aussi =====
* **(fr)** [[developpez.net/forums/d1615066/webmasters-developpement-web/serveurs-apache-iis/apache/cohabitation-apache2-nginx/]]
----
//Basé sur << [[https://www.developpez.net/forums/d1615066/webmasters-developpement-web/serveurs-apache-iis/apache/cohabitation-apache2-nginx/|Cohabitation apache2 et nginx]] >> par developpez.net.//