Server site optimisation

Setting up and configuring the Apache and Nginx server for the website.

FIntroduction

Web server - serves the operation of the site on the Internet, where it acts as an intermediary between the client and the server. The web server takes, for each user request, content from the server and transmits it to the network.

The main task is to simultaneously serve various requests from many users, therefore, in order to reduce the load on the server and increase the load on sites, it is necessary to correctly configure the configuration files of the web server where the site is located.

In simple words: a web server is a tool for connecting a server to a client and vice versa.

Web servers

In today's world, there are many web servers that help to receive and send content between a server and a client on the Internet. At the moment, some of the popular web servers are nginx and apache.

We won’t specifically compare the difference between apache and nginx, just how they differ and why they choose one or another web server, since both have advantages and disadvantages. Therefore, it will be considered in general what they are and how to interact with them, namely the configuration settings for this software.

Apache

When a client visits a page, its browser sends a request to the server and Apache returns a response with all the requested files: text, image, and so on using the http/https protocol. The web server is responsible for a secure and fast connection between the client and the server.

Modules allow server administrators to enable or disable additional functionality. There are various modules: security, caching, URL editing, password authentication and others.

With configuration files, you can set your own configuration via the .htaccess file. This file is a configuration file (or add-in file) and helps you determine the desired configurations for your site.

Nginx

Nginx is a web server and mail proxy that runs on Unix-like operating systems. In the fall of 2004, the first publicly available release was released. The use of nginx is useful primarily for static websites and as a reverse proxy server in front of dynamic sites.

Main functions:

  • maintenance of requests, index files, automatic creation of a list of files.
  • proxying without caching, simple load balancing and fault tolerance.
  • caching support for accelerated proxying.
  • modularity and filters.
  • several subqueries on the same page (and in the SSI filter) are executed in parallel.

Apache or Nginx?

Nginx is a newer web server software that was released in 2004. It was created to solve the c10k problem (the 10,000 connections problem). This means that web servers using threads cannot process client requests from more than 10,000 connections at the same time.

Apache uses a threaded structure and high traffic sites may experience performance issues. Nginx is one of the web servers that was aimed at solving the c10k problem.

Nginx has an event-driven architecture that does not create a new process for each request, instead it processes each incoming request on a single thread. This master process manages several worker processes that handle requests directly.

Web server setup

Typically, web server configuration files are configured separately and individually for each site or framework, but there are a number of different general settings for this file that apply to all sites.

The main settings that are used on the server are working with url editing modules and caching, since these two modules play one of the important roles in SEO and site performance both in terms of loading and response time.

The caching module allows the client to cache files for a certain (specified) period. Various types of images, queries, html pages, styles, scripts, fonts and more are cached.

The url editing module allows you to validate page urls and set rules for them: redirect (redirect) to another page or site, edit the contents of the url (for example, remove .html), point to error pages (for example, 404) and more.

Apache: .htaccess

Setting Apache configuration in .htaccess file. All add-ons are written in one file, so there is no need to create new files, there is only one - .htaccess in the root (root directory) of the site.

An example of a basic full-fledged file setup that includes the following modules: view in github

Nginx: .conf

Setting Nginx configuration in my-nginx.conf file. All settings are written in one file, so no new files need to be created.

For the configuration file under Nginx, unlike apache, you can set any names, for example cache-ng.conf and in Nginx itself specify for the folder on the server which file to use as a configuration.

An example of a basic full-fledged file setup that includes the following modules: view in github

Share it!

Hey, help me and share that page! Just only one click!