Day 33: What is Webserver (NGINX)

Day 33: What is Webserver (NGINX)

#90daysofdevops

🚀 Introduction

In this blog we'll understand what is webserver, where we use webserver, why we use webserver & why you should use NGINX web server


🔸First understand why we need webserver

  • Web server are essential for hosting and delivery web content. Without web servers website and application wouldn't be accessible on the internet. They play a crucial role in facilitating communication between client and severs.

Before understanding what is web server understand what is forward proxy and reverse proxy

Forward proxy: A forward proxy or a web proxy act as an intermediary between client device and the internet. It forwards request from client to server and retrieve the response, helping to hide the clients identity & Improve security.

Reverse proxy: It forwards client request to appropriate server, retrieve the response and send them back to the client. Unlike forward proxy that serves client and the reverse proxy serves enhancing security, load balancer & performance.

Nginx can do reverse proxy, load balancing & http cache.


🔸What is webservers

  • Web servers are software application that handle and respond to incoming requests over the http or https protocols. They serve web pages and other web content to users browser.

OR

  • A web server is a fundamental component of the internet Infrastructure responsible for serving web content to users. It play a Central role in handling and delivering web request and responses ensuring that website and web application are accessible and functional to users worldwide.

🔸What is Apache & NGINX

  • Apache and nginx are popular web servers used to deliver web pages to a user browser.
  • They handle the processing of a http requests, serving web pages and managing communication between clients and web application.

🔸When deploying on AWS, using Nginx has several advantages:

  • Reverse Proxy: Nginx allows you to manage your application servers, enabling load balancing and performance improvements.

  • Static Content: Efficiently serving static files, Nginx enhances website speed.

"Static content serving" means that a web server like Nginx, efficiently handles and serves unchanging files such as HTML pages, images, CSS stylesheets, and JavaScript files. These files remain the same for all users and are not dynamically generated based on user actions. Serving static content directly improves response time, reduces server load, and enhances overall website performance.

  • Security: Nginx's security features, such as DDoS attack prevention and SSL/TLS support, protect your application.

"DDoS attack means": DDoS stands for distributed denial of service. The aim of DDoS attack is to make service or website unavailable to its user by flooding it with excessive traffic. This can result in slowed performance or complete unavailability of the online service.

"SSL & TLS means": SSL (Secure Socket layer) & TLS (Transport layer security) are cryptographic protocols designed to secure communication over a computer network. SSL & TLS are protocols that encrypt data to ensure secure communication on the internet. TLS is the updated and more secure version commonly use for protecting sensitive information during online transactions and data exchange.

  • Flexible Configuration: Nginx provides flexibility in configuring according to your requirements.

🔸What is apache, nginx & the difference between them.

  • Both are popular web servers. Apache is known for its flexibility and feature richness, while nginx is pressed for its high performance and efficiency, especially in handling concurrent connection.

  • Concurrent connection refer to the number of samantha's connection that the server can handle. (10000 No. of concurrent connection nginx can handle)


🔸What is a web server, and what is its primary function in the context of the internet?

  • A web server is a software application or hardware device that serves as the foundation for delivering web content over the internet. Its primary function in the context of the internet is to respond to requests from clients, typically web browsers, by sending them the requested web pages, files, or data. Here's a more detailed explanation of a web server's role and function:

Role of a Web Server:

1. Request Handling: When a user or client (such as a web browser) requests a web page or a resource (like an image, video, or document), the request is sent to a web server. The web server receives and processes this request.

2. Content Storage: Web servers store the web content, which may include HTML files, images, CSS stylesheets, JavaScript scripts, and more. These files are organized in directories on the server's file system.

3. Content Retrieval: The web server locates the requested resource based on the URL (Uniform Resource Locator) in the client's request. It then retrieves the relevant file or generates dynamic content by running server-side scripts if necessary.

4. Response Generation: After obtaining the requested content, the web server generates an HTTP (Hypertext Transfer Protocol) response, which includes the requested data and metadata, such as the content type and status code.

5. Data Transmission: The web server sends the HTTP response back to the client's browser over the internet using the HTTP protocol. This transmission typically occurs over port 80 for HTTP or port 443 for HTTPS (secure HTTP).

6. Communication: Web servers are designed to handle multiple concurrent connections, allowing them to serve content to multiple clients simultaneously. They manage these connections efficiently to minimize response times.

Functions of a Web Server:

1. Content Delivery: The primary function of a web server is to deliver web content to users' browsers. This content can be static (unchanging) or dynamic (generated on-the-fly based on user input or other factors).

2. Request Routing: Web servers can route requests to the appropriate resources based on the URL or other request parameters. This allows them to serve different web pages or files based on user requests.

3. Security: Web servers often include security features to protect against various threats, such as DDoS (Distributed Denial of Service) attacks, intrusion attempts, and unauthorized access. They can enforce secure communication using protocols like HTTPS.

4. Load Balancing: In large-scale applications, multiple web servers may be deployed behind a load balancer. The load balancer distributes incoming traffic among these servers to ensure even resource utilization and high availability.

5. Logging and Analytics: Web servers can log access requests, errors, and other events. These logs are valuable for monitoring server performance, troubleshooting issues, and analyzing user behavior through web analytics tools.

6. Integration with Databases: Web servers can communicate with databases to retrieve dynamic content. They execute server-side scripts, such as PHP, Python, or Ruby, to generate HTML content based on data from databases.

7. Caching: Web servers can cache frequently accessed content to reduce server load and improve response times. This is especially useful for static content and can be implemented at both the server and content delivery network (CDN) levels.


🔸Why you should use nginx

  • Security feature.

  • Static files serve

  • Because we want to deliver our application with good security.

  • We can use NGINX as a load balancer.

  • Because we have to treat our user seriously, the website or application should run 24 hours.

  • Nginx is 2.5x is faster to deliver static content

  • Easy to use

Which one you should use according to market share

Apache 👎

Nginx 👍


🔸Architecture of Nginx Webserver


How we can configure nginx webservers

https://docs.nginx.com/nginx/admin-guide/web-server/web-server/


How we can transfer traffic from http to https using webservers

To redirect HTTP traffic to HTTPS, you can configure your web server to send a 301 or 302 redirect response for all HTTP requests, pointing them to the corresponding HTTPS URL. This is typically done by modifying your server configuration. If you specify the web server you're using, I can provide more specific instructions.

Nginx:

  • Open your Nginx configuration file (typically found at /etc/nginx/nginx.conf or /etc/nginx/sites-available/default).

  • Add the following lines inside the server block:

server {
    listen 80;
    server_name 
example.com;
    return 301 
https://$host$request_uri;
}
  • Save the file and restart Nginx

IIS (Internet Information Services):

- Open IIS Manager.

- Select your site, and go to "HTTP Redirect" under "IIS" or "Site" features.

- Check "Redirect requests to this destination" and enter https://example.com.

- Check "Redirect all requests to exact destination" and choose "Permanent (301)".

- Click Apply

Remember to replace "example.com" with your actual domain. After making these changes, restart your web server for the configuration to take effect.


Undertand the file system of nginx

Nginx uses a hierarchical file system structure, similar to many other web servers. Key directories include:

1. /etc/nginx: Configuration files are here, including nginx.conf for global settings and sites-available for individual site configurations.

2. /usr/share/nginx/html: Default root directory for web content. You can place your website files here.

3. /var/log/nginx: Log files are stored here. The main log is in access.log, and errors are logged in error.log.

4. /etc/nginx/sites-available and /etc/nginx/sites-enabled: These directories manage site configurations. Sites are defined in sites-available and symlinked to sites-enabled to activate them.

  1. /etc/nginx/snippets: Contains reusable configuration snippets that can be included in various site configurations.

Understanding and customizing the configuration files in these directories allows you to tailor Nginx to your specific needs.


Nginx's main folders are:

1. /etc/nginx: Configuration files.

2. /usr/share/nginx/html: Default web content location.

3. /var/log/nginx: Log files.

4. /etc/nginx/sites-available and /etc/nginx/sites-enabled: Manage site configurations.

5. /etc/nginx/snippets: Reusable configuration snippets.


Thanks for reading to the end; I hope you gained some knowledge.❤️🙌

Linkedln

Twitter

Github