install nginx | zuhdi.org

Install Nginx

Environment

  • Debian 9.7 x64
  • Nginx 1.10.3

Excerpt

1. Install Nginx

root@athos:~# apt-get update && apt-get -y upgrade && apt-get -y dist-upgrade

root@athos:~# apt-get -y --no-install-recommends install nginx

root@athos:~# systemctl enable --now nginx.service
Synchronizing state of nginx.service with SysV service script with 
  /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable nginx

root@athos:~# nginx -v
nginx version: nginx/1.10.3

2. Server blocks (Virtual hosts)

root@athos:~# mkdir -p /var/www/athos.host/html

root@athos:~# mkdir -p /var/www/chimera.host/html

root@athos:~# chmod -R 755 /var/www

root@athos:~# echo "athos.host" > /var/www/athos.host/html/index.html

root@athos:~# echo "chimera.host" > /var/www/chimera.host/html/index.html

cat <<EOF > /etc/nginx/sites-available/athos.host
server {
  listen 80;
  listen [::]:80;

  root /var/www/athos.host/html;
  index index.html index.htm index.nginx-debian.html;

  server_name athos.host www.athos.host;

  location / {
    try_files $uri $uri/ =404;
  }
}
EOF

root@athos:~# cat <<EOF > /etc/nginx/sites-available/athos.host
> server {
>   listen 80;
>   listen [::]:80;
>
>   root /var/www/athos.host/html;
>   index index.html index.htm index.nginx-debian.html;
>
>   server_name athos.host www.athos.host;
>
>   location / {
>     try_files $uri $uri/ =404;
>   }
> }
> EOF

cat <<EOF > /etc/nginx/sites-available/chimera.host
server {
  listen 80;
  listen [::]:80;

  root /var/www/chimera.host/html;
  index index.html index.htm index.nginx-debian.html;

  server_name chimera.host www.chimera.host;

  location / {
    try_files $uri $uri/ =404;
  }
}
EOF

root@athos:~# cat <<EOF > /etc/nginx/sites-available/chimera.host
> server {
>   listen 80;
>   listen [::]:80;
>
>   root /var/www/chimera.host/html;
>   index index.html index.htm index.nginx-debian.html;
>
>   server_name chimera.host www.chimera.host;
>
>   location / {
>     try_files $uri $uri/ =404;
>   }
> }
> EOF

root@athos:~# ln -s /etc/nginx/sites-available/athos.host /etc/nginx/sites-enabled/

root@athos:~# ln -s /etc/nginx/sites-available/chimera.host /etc/nginx/sites-enabled/

root@athos:~# ls -lF /etc/nginx/sites-enabled/
total 0
lrwxrwxrwx 1 root root 37 May 13 11:04 athos.host 
                  -> /etc/nginx/sites-available/athos.host
lrwxrwxrwx 1 root root 39 May 13 11:04 chimera.host 
                  -> /etc/nginx/sites-available/chimera.host
lrwxrwxrwx 1 root root 34 May 13 10:58 default 
                  -> /etc/nginx/sites-available/default

root@athos:~# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

root@athos:~# systemctl restart nginx.service

Hugo. Malte Kiefer & Zuhdi Najib.