Requirement
- Web Server Running (Apache2 on IP
10.10.10.1:80
) - Reverse Proxy (Nginx on IP
10.10.10.2
)
Assumption
It is assumed that a web server is already running. In this example, the web server runs on IP 10.10.10.1:80
.
The reverse proxy server will be running on a different VM or server with IP 10.10.10.2
.
Installation
Install Nginx
apt install nginx
Unlink default
config nginx
unlink /etc/nginx/sites-enabled/default
Create file reverse-proxy.conf
in /etc/nginx/sites-availible
touch /etc/nginx/sites-available/reverse-proxy.conf
Add the following configuration to the file:
server {
listen 80;
# listen 443 ssl;
server_name www.domain.com;
access_log /var/log/nginx/reverse-proxy-access.log;
error_log /var/log/nginx/reverse-proxy-error.log;
# ssl on;
# include snippets/ssl-defaults.conf;
# include snippets/proxy-defaults.conf;
location / {
#Set header Proxynya
proxy_redirect off;
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 Accept-Encoding "";
#Tujuan permintan diteruskan
proxy_pass http://10.10.10.1/;
}
}
Then, create a symbolic link for reverse-proxy.conf
in sites-enabled
:
ln /etc/nginx/sites-available/reverse-proxy.conf /etc/nginx/sites-enabled/reverse-proxy.conf
Check if the configuration is correct:
nginx -t
Restart Nginx and enable
it to start automatically on boot:
systemctl restart nginx
systemctl enable nginx
Test the setup by accessing the reverse proxy server's IP.
If the configuration is correct, you should see the web server from Server 1.
Happy trying!
Top comments (0)