How to install and setup Nginx on Debian Linux 9

http‮/:s‬/www.lautturi.com
How to install and setup Nginx on Debian Linux 9

To install and set up Nginx on Debian Linux 9, you will need to have root privileges or access to a user with sudo privileges.

  1. First, update the package repository by running the following command:
sudo apt update
  1. Install Nginx by running the following command:
sudo apt install nginx
  1. Once the installation is complete, Nginx will start automatically. You can check the status of the Nginx service by running the following command:
systemctl status nginx
  1. To make sure that Nginx starts automatically at boot time, run the following command:
systemctl enable nginx
  1. To access the Nginx web server, open a web browser and go to the following URL:

http://localhost/

You should see the default Nginx welcome page.

  1. The main configuration file for Nginx is located at /etc/nginx/nginx.conf. You can edit this file to customize the behavior of Nginx. For example, you can change the port that Nginx listens on, enable SSL/TLS encryption, or set up virtual hosts.

  2. To create a virtual host, create a new configuration file in the /etc/nginx/sites-available directory. For example:

sudo vi /etc/nginx/sites-available/example.com

In the configuration file, specify the server name, document root, and any other options that you want to use. For example:

server {
    listen 80;
    server_name example.com www.example.com;
    root /var/www/example.com;
    index index.html index.htm;
}
  1. To enable the virtual host, create a symbolic link from the configuration file in the /etc/nginx/sites-enabled directory. For example:
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
  1. Test the Nginx configuration by running the following command:
nginx -t

If the configuration is valid, you should see a message saying "syntax is ok" and "configuration is ok".

  1. If the configuration is valid, reload Nginx to apply the changes by running the following command:
systemctl reload nginx

That's it! Nginx should now be installed and set up on your Debian Linux 9 system. You can use it to serve web content and set up virtual hosts.

Created Time:2017-10-28 21:39:04  Author:lautturi