Setting up the NGINX reverse proxy

Although the igweb web server instance, a Go application, can single-handedly fulfill the major needs to serve IGWEB, it is more advantageous to have the igweb, web server instance, sit behind a reverse proxy.

A reverse proxy server is a type of proxy server that will service a client request by dispatching the request to a designated destination server (in this case, igweb), get the response from the igweb server instance, and send the response back to the client.

Reverse proxies come in handy for several reasons. The most important reason for the immediate benefit of releasing IGWEB is that we can enable GZIP compression on the outbound static assets. In addition to that, reverse proxies also allow us to easily add redirect rules to control the flow of traffic as the need arises.

NGINX is a popular high performance web server. We will be using nginx as the reverse proxy that sits in front of the igweb web server instance. Figure 11.2 depicts a typical reverse proxy configuration, where a web client will issue a HTTP request over port 80 and nginx will service the request by sending the HTTP request to the igweb server instance over port 8080, retrieving the response from the igweb server and sending the response back to the web client over port 80:

Figure 11.2: The reverse proxy configuration

Here is a listing of the nginx configuration file, nginx.conf, that we will use to run nginx as a reverse proxy:

user igweb;
worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

sendfile on;
keepalive_timeout 65;

gzip on;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_types text/plain application/javascript text/css;
gzip_vary on;
gzip_comp_level 9;

server_tokens off;

server {
listen 80;
access_log /var/log/nginx/access.log main;
location / {
proxy_pass http://192.168.1.207:8080/;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
}
}

There are two sections of settings that are of particular interest to us, the section to enable GZIP compression and the section for proxy settings.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.247.53