Install Nginx

Installation environment

Ubuntu 20.04


The installation process

Nginx sudo apt-get install nginxCopy the code

Basic operation

Viewing the Installation Directory

sudo nginx -t
Copy the code
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Copy the code

The default installation directory is /etc/nginx/

Common operations

Start the

sudo service nginx start
Copy the code

stop

sudo service nginx stop
Copy the code

restart

sudo service nginx restart
Copy the code

uninstall

Delete nginx, -purge includes configuration files

sudo apt-get --purge remove nginx
Copy the code

Remove all unused software packages

sudo apt-get autoremove
Copy the code

List nginx-related software and delete it

dpkg --get-selections|grep nginx sudo apt-get --purge remove nginx sudo apt-get --purge remove nginx-common sudo apt-get  --purge remove nginx-coreCopy the code

Check the processes that nginx is running and kill them if they exist

ps -ef |grep nginx
sudo kill -9 XXX
Copy the code

Configure Nginx

The latest version of nginx configuration consists of four files:

  1. conf.d: User-defined CONF configuration file
  2. sites-available: Configuration file of the default system Settings
  3. sites-enabledBy:sites-availableConfiguration file transformation generated in
  4. nginx.conf: Summarize the contents of the previous three configuration files and set required parameters

When deploying the required Web service, we can copy the default file in site-enabled to conf.d and change the name to **.conf, and then configure it