Nginx
Nginx is an open source web server, that can also be used as a reverse proxy, load balancer, http cache etc.
What are some usecases to use nginx?
- Static content server
- Reverse proxy
- SSL
- Cache
- Websocket proxy
- API Gateway
- Load balancer
nginx is used for lots of things as shown above. We will implement some of the usecases.
Installation
sudo apt updatesudo apt install nginxAbove should have installed the nginx on your system.
Let’s check.
sudo nginx -vsudo nginxThis should start an nginx server on port 80, try visiting thw website on the browser.
nginx.conf
Let’s open the nginx.conf file and see how it looks like.
sudo vi /etc/nginx/nginx.confThe nginx config file will be like like following:
user nginx;worker_processes auto;
error_log /var/log/nginx/error.log notice;pid /var/run/nginx.pid;
events { worker_connections 1024;}
# We will create server blocks inside httphttp { 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"';
access_log /var/log/nginx/access.log main;
sendfile on; #tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;}We will be making changes for creating server inside of the http block in next.