A reverse proxy is a server that sits in front of web servers and forwards client (e.g., web browser) requests to those web servers.
It can receive requests for multiple domains, subdomains and ports/protocols and rout these according to its configuration to the target servers.
Additionally, reverse proxies are used to increase security, performance, and reliability of the web infrastructure. Reverse proxies can provide additional functionalities such as load balancing, SSL termination, and caching. (not used as of now)
The following default.conf configuration file routes all http and https requests to a given server. server_name _; acts as wild card to listen to all interfaces, domains and requested ips.
It provides a fallback, if no other configuration file matches the request
# http routing
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
location / {
proxy_pass http://drg-fs01;
proxy_set_header Host $host;
}
}
# https routing
server {
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
# note: will lead to certificate trust warnings
ssl_certificate /etc/nginx/ssl/nginx-selfsigned.crt;
ssl_certificate_key /etc/nginx/ssl/nginx-selfsigned.key;
location / {
proxy_pass http://drg-fs01;
proxy_set_header Host $host;
}
}
To effectively manage traffic for your domain and any associated subdomains through the Nginx reverse proxy, follow the following instructions:
sudo nano /etc/nginx/sites-available/your_site_name.conf
sites-enabledsudo ln -s /etc/nginx/sites-available/your_site.conf /etc/nginx/sites-enabled/
# https requests
server {
listen 443 ssl;
server_name knowledgebase.dragunarts.com;
location / {
proxy_pass http://drg-knowledgebase;
proxy_set_header Host $host;
}
}
server {
listen 443 ssl;
server_name knowledgebase.julianbechtold.ch;
location / {
proxy_pass http://drg-knowledgebase;
proxy_set_header Host $host;
}
}
server {
listen 443 ssl;
server_name knowledgebase.julianbechtold.com;
location / {
proxy_pass http://drg-knowledgebase;
proxy_set_header Host $host;
}
}
# http requests
server {
if ($host = knowledgebase.dragunarts.com) {
return 301 https://$host$request_uri;
}
listen 80;
server_name knowledgebase.dragunarts.com;
return 404;
}
server {
if ($host = knowledgebase.julianbechtold.ch) {
return 301 https://$host$request_uri;
}
listen 80;
server_name knowledgebase.julianbechtold.ch;
return 404;
}
server {
if ($host = knowledgebase.julianbechtold.com) {
return 301 https://$host$request_uri;
}
listen 80;
server_name knowledgebase.julianbechtold.com;
return 404;
}
sudo certbot --nginx
next you need to follow the prompts of certbot
sudo nginx -t
sudo systemctl reload nginx