|
|
#How to make reverse Proxy with NGINX
|
|
|
|
|
|
>Cas : Tu as une adresse IP public et désire hébergé différent nom de sous-domaine et/ou différent service sur différents serveur VM/CT (pense Docker).
|
|
|
|
|
|
Rien de plus simple configure un reverse proxy à l'aide de NGINX ;)
|
|
|
|
|
|
Voici un exemple du fichier de config NGINX situé sur la machine répondant au port 80 sur l'IP Public
|
|
|
|
|
|
nano /etc/nginx/site-available/bob
|
|
|
|
|
|
server {
|
|
|
listen [::]:80 ipv6only=off; ## par exemple écoute sur le port http donc 80 (mais ça peut-être 443 pour https)
|
|
|
server_name bob.chez.moi; ## par exemple cette config est spécifique au site devant répondre à bob.chez.moi
|
|
|
access_log /var/log/nginx/bob-chez-moi-access.log;
|
|
|
error_log /var/log/nginx/bob-chez-moi-error.log;
|
|
|
large_client_header_buffers 4 8k;
|
|
|
location / {
|
|
|
|
|
|
proxy_set_header Host $host;
|
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
|
|
|
|
# Fix the “It appears that your reverse proxy set up is broken" error.
|
|
|
proxy_pass http://IPduVraiServerBOB:PortS'ilya; ## par exemple bob.chez.moi est en réalité sur l'IP http://192.168.0.22:80 ou https://192.168.0.22:443
|
|
|
proxy_read_timeout 90;
|
|
|
proxy_redirect http://192.168.0.22 http://bob.chez.moi; ##
|
|
|
}
|
|
|
}
|
|
|
|
|
|
##on OpenMediaVault
|
|
|
|
|
|
Installer le plugins NGINX
|
|
|
|
|
|
Dans Services -> Nginx (Website) l'onglet servers
|
|
|
|
|
|
Ajouter un site en spécifiant le Type d'hote (host type) : Name-based
|
|
|
pour ensuite donner le nom du domaine/sous-domaine : bob.chez.moi
|
|
|
et dans la partie EXTRA OPTIONS
|
|
|
|
|
|
on colle la partie proxy ci dessus, c-à-d :
|
|
|
|
|
|
location / {
|
|
|
|
|
|
proxy_set_header Host $host;
|
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
|
|
|
|
# Fix the “It appears that your reverse proxy set up is broken" error.
|
|
|
proxy_pass http://192.168.0.22;
|
|
|
proxy_read_timeout 90;
|
|
|
|
|
|
proxy_redirect http://192.168.0.22 http://bob.chez.moi;
|
|
|
} |