NGINX WEB Server


# STEP8

# install lightweight web server (nginx) to:
# get access to covers (album artwork) from MPD client
# use a internet browser with MPD WEB Client MyMPD on your desktop PC, tablet or phone to play and browse your music library

# Install the web server and dependencies:

  1. $ sudo apt-get install nginx php-curl php-sqlite3 php-gd php-json php-xml php-mbstring php-fpm php-intl imagemagick

# Edit configuration:

  1. $ sudo nano /etc/nginx/nginx.conf

# add this lines under gzip section

 gzip on;
 gzip_vary on;
 gzip_buffers 16 8k;
 gzip_comp_level 6;
 gzip_min_length 1000;
 gzip_proxied expired no-cache no-store private auth;
 gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/vnd.ms-fontobject application/x-font-ttf font/opentype image/svg+xml image/x-icon;
 gzip_disable msie6;
 gzip_http_version 1.1;

# CTRL+O to save
# CTRL+X to exit


# Add an alias to get access to album cover (artwork) from http://192.168.x.x/music/…cover.jpg:
# add a redirection to myMPD (MPD WEB Client)
# Edit the default configuration and to write new server configuration below :

  1. $ sudo nano /etc/nginx/sites-available/default

# php is enabled (see the equalizer UI doc)
# and IPv6 is disabled by default on your LAN (the line listen [::]:80 default_server; is commented)
# BEWARE: php version 8.2 is installed by default in edition 2024 (bookworm),
# if Debian buster is installed and you didn’t update php change the fastcgi_pass line to your php version 7.x
# example for version 7.4: fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;

	
server {
        listen 80 default_server;
#       listen [::]:80 default_server;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.php;

        server_name _;

        location /favicon.ico {
                alias /var/www/html/ml_play.png;
        }

        location /music {
                alias /mnt/media;
        }

        location /mympd/ {
                return 301 http://$host:8080/;
        }

        location /eq/ {
                return 301 http://$host:80/;
        }

        location ~* \.(css|js|jpg|jpeg|png|gif|ico|svg)$ {
                try_files $uri $uri/ =404;
        }

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
        }

        location / {
                try_files $uri $uri/ /index.php?$query_string;
        }
}

# CTRL+O to save
# CTRL+X to exit

# OPTIONAL
# create temp directory to save settings

  1. $ sudo mkdir /var/www/html/tmp

# add the user pi (your username) to group www-data

  1. $ sudo usermod -a -G www-data pi

# set permission

  1. $ sudo chown -R www-data:www-data /var/www
  2. $ sudo chmod -R g+rwX /var/www

# create a soft link of the web directory
# to get access to it from your home

  1. ln -s /var/www/ ~/www

# restart service

  1. $ sudo systemctl restart nginx


  1. $ sudo systemctl status nginx

# optional: reboot

  1. sudo reboot

# that’s it!


# now you can get access to your album covers from http

# type this address in your browser (replace with IP of the server and path to music that contains folder.jpg or cover.jpg )
# http://192.168.XX.XX/music/<song_path>/cover.jpg

# ATTENTION: you have to enter the IP of MusicLounge Audiophile Server and NOT the ip of your Music library share point
# http://192.168.1.xxx/music is now the link to get access to your musics from any music players whatever the platform (Android, iOS, Windows, Linux, …)

# FOR EXAMPLE

http://192.168.1.xxx/music/Bach/Toccata/cover.jpg


# start a new SSH session, it’s time to install the main part of this audiophile server – Music Player Daemon (AKA MPD)

Click the button NEXT below to continue…