como-instalar-y-configurar-nginx-en-raspberry-pi

How to Install and Configure Nginx on Raspberry Pi

  • 3 min

Nginx is a high-performance web server widely used and ideal for hosting websites, web applications, and services on your Raspberry Pi.

Nginx (pronounced “engine-x”) is an open-source web server and reverse proxy known for its high performance, low resource consumption, and ability to handle a large number of simultaneous connections.

One of the things that stands out about Nginx is its ease of acting as a reverse proxy and load balancer, making it a very useful tool in high-demand environments.

Installing Nginx on Raspberry Pi

To install Nginx on your Raspberry Pi, open a terminal and run the following command:

sudo apt install nginx

Wait for it to install, that’s it. It’s that easy! When it’s ready, we can verify that Nginx is running with:

sudo service nginx status

If at any point we need to stop, start, or restart Nginx we can do it with these commands:

sudo service nginx stop sudo service nginx start sudo service nginx restart

Configuring Nginx

The main Nginx configuration is located in the /etc/nginx/ directory. The main configuration file is /etc/nginx/nginx.conf. By default, it has a tip like the following.

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
	worker_connections 768;
	# multi_accept on;
}

http {

	##
	... several configuration items that we omit... 
	##

	include /etc/nginx/conf.d/*.conf;
	include /etc/nginx/sites-enabled/*;
}

Copied!

Where you see that the last line loads all the .conf files from the /etc/nginx/conf.d/ folder and all files from /etc/nginx/sites-available/.

To keep everything organized, you will generally perform the configuration for each site in separate files in the /etc/nginx/sites-available/ directory.