Nginx Server

Sayeed Far Ooqui
2 min readDec 9, 2020

Open source, high performance web server and proxy server

Proxy: It is making the request on behalf of the client

In forward proxy server will never “learn” who the client was (the client’s IP address); it will only know the proxy. However, the client definitely knows the server

In reverse proxy the client will never “learn” who was the actual server (the server’s IP address) (with some exceptions); it will only know the proxy. The server will or won’t know the actual client, depending on the configurations of the reverse proxy.

In effect, whereas a forward proxy hides the identities of clients, a reverse proxy hides the identities of servers.

Reverse Proxy: Acting on behalf of service/content producer.t protects the server from users.

NGINX vS APACHE

nginx — single thread, all request handled by one single thread. both proxy server and webserver. better performance

Apache — multi thread. one thread handles one request at time. web server only

Command

sudo service nginx start -- start nginx
sudo service nginx stop -- stop nginx
sudo service nginx restart -- restart nginx
sudo service nginx enable -- start enable

Syntax

http {  
upstream backend {
server backend1.example.com weight=5;
server backend2.example.com;
server 192.0.0.1 backup;
}

server {
location / {
proxy_pass http://backend;
}
}
}

Load Balancing

  1. Round Robin (default)

requests are distributed equally across the servers, with server weights taken into consideration. In above example out of 6, 5 request will goes to server backend1.example.com and 1 request goes to backend2.example.com. and last back up server will up , if all other server goes down.

2. Least Connections:

request is sent to the server with the least number of active connections

upstream backend {  
least_conn;
server backend1.example.com;
server backend2.example.com;
}

3. Random, Least Time, Ip hash etc

Health check

send request to each member in upstream and check check whether its down or not. it continuously test out upstream server.

INTERVIEW

question 1) Mention what is the Master and Worker Processes in Nginx Server?

  • Master processes: It reads as well as evaluates configuration and maintains worker processes.
  • Worker processes: It actually does the processing of the requests.

question 2) Explain how you can start Nginx through a different port other than 80?

To start Nginx through a different port, you have to go to /etc/Nginx/sites-enabled/ and if this is the default file, then you have to open file called “default.” Edit the file and put the port you want

question 3) In Nginx, explain how you can keep double slashes in URLs?

To keep double slashes in URLs you have to use merge_slashes_off;

question 4) Nginx upstream modules?

module defined server

--

--