Nginx -1

·

2 min read

NGINX is an open-source reverse proxy and web server designed for scale. It exploded in popularity as the first line of defense against backend infrastructures. Whether as a caching layer, load balancer, API gateway or Web server, NGINX does it all.

A reverse proxy server is a server that sits in front of web servers and directs client requests to the appropriate web server. This configuration can be used to improve the security, scalability, and reliability of web applications.

Install Nginx

Install nginx using the following command

apt-get update
apt-get install nginx

After accepting the procedure, apt-get will install Nginx and any required dependencies to your server.

systemctl stop nginx

systemctl start nginx

systemctl restart nginx

systemctl reload nginx

By default, NGINX is configured to start automatically when the server boots. If this is not what you want, you can disable this behavior by typing:

systemctl disable nginx

To re-enable the service to start up at boot

systemctl enable nginx

To test your config file

nginx -t

Important NGINX Files and Directories

  • /var/www/html: The actual web content, which by default only consists of the default Nginx page you saw earlier, is served out of the /var/www/html directory. This can be changed by altering NGINX configuration files.

Edit the HTML file

Restart the nginx server

systemctl restart nginx

How to host a simple website on Nginx

Install Nginx Server

Goto /var/www/html

Restart the nginx server

Server Configuration

  • /etc/nginx: The NGINX configuration directory. All of the Nginx configuration files reside here.

  • /etc/nginx/nginx.conf: The main NGINX configuration file. This can be modified to make changes to the NGINX global configuration.

  • /etc/nginx/conf.d — Hold our server configuration files.

  • /etc/nginx/sites-available — Hold our server configuration file

  • /etc/nginx/sites-enabled — Hold our server configuration file

  • /etc/nginx/sites-available/default — Welcome to the Nginx page configuration file

Server Logs

  • /var/log/nginx — Nginx Store log files

  • /var/log/nginx/access.log: Every request to your web server is recorded in this log file unless and until NGINX is configured to do otherwise.

  • /var/log/nginx/error.log: Every NGINX error will be recorded in this log only.

Where to store the logs file, if you change the location you can modify

/etc/nginx/nginx.conf

Create a Extension Site

First, unlink the default

/etc/nginx/sites-enabled/

unlink default

Created files sites.conf

Check the configuration file nginx conf -t

Restart the Nginx server. Check the tab /sites

Check log files for the sites tab

/var/log/nginx/

Only once time refresh the page I got one log file is there

Will See more ....