GNU/Linux {docs}

Nginx Block Server

For static pages

Find out codename version: $ lsb_release -a

$ sudo wget https://nginx.org/keys/nginx_signing.key
$ sudo apt-key add nginx_signing.key
$ sudo vi /etc/apt/sources.list
deb https://nginx.org/packages/mainline/debian/ <CODENAME> nginx
deb-src https://nginx.org/packages/mainline/debian/ <CODENAME> nginx
$ sudo apt update
$ sudo apt install nginx
$ sudo mkdir -p /var/www/example.com
$ sudo cp /var/www/html/index.nginx-debian.html /var/www/example.com/index.nginx-debian.html
$ sudo chown -R www-data: /var/www/example.com
$ sudo echo "192.168.1.56 example.com" >> /etc/hosts
$ sudo nano /etc/nginx/conf.d/example.com.conf
server {
listen 80;
listen [::]:80;
root /var/www/example.com;
index index.nginx-debian.html;
server_name example.com www.example.com;
#access_log /var/log/nginx/example.com.access.log;
#error_log /var/log/nginx/example.com.error.log;
location / {
try_files $uri $uri/ =404;
}
}
  • Comment or delete the following line in /etc/nginx/nginx.conf:

include /etc/nginx/sites-enabled/*;

$ sudo nginx -t
$ sudo systemctl restart nginx
  • Go to example.com in your browser and test

For dynamic content

All the steps above plus the following:

# apt install php-fpm php-mysql

  • Check that the information below appears in /etc/php/7.2/fpm/pool.d/www.conf :
...
user = www-data
group = www-data
...
listen.owner = www-data
listen.group = www-data
...
  • Add the following paragraph in /etc/nginx/conf.d/example.com.conf:
# pass PHP scripts to FastCGI server
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}