User Tools

Site Tools


server-block-setup

This is an old revision of the document!


Server Blocks Setup

Purpose and Scope

In this document, we will describe the steps to add server blocks (SB) to a dokku-nginx environment in order to be able to access web application without docker containers. We will not describe here the necessary steps to install REDCap (RC) or Grafana (GF). Nor will we discuss user management, database configuration, rights and data backup related to these web applications.

Prerequisite

  • Ubuntu server 18.04
  • Nginx 1.14.0
  • sudo privileges on the server.

Material

:?:

Server Blocks setup

2. Server blocks setup When using nginx server, we need SB (virtual hosts in Apache) to be able to access more than one domain in a single sever. - Set up document root directories We need to create these directories for each needed sites. sudo mkdir -p /var/www/redcap sudo mkdir -p /var/www/grafana

Assign the current user and give him right rights on the created folders (do not use root user). sudo chown -R $USER:$USER /var/www/redcap sudo chown -R $USER:$USER /var/www/grafana

sudo chmod -R 755 /var/www

- Create a test file for each site nano /var/www/{site}/ index.php

  Edit each php file with some test content <?php phpinfo();

- Create server Block files for each domain Create the first SB and use the default template. sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/redcap

Edit the new SB sudo nano /etc/nginx/sites-available/example.com

Here an example of SB file configuration server {

      listen 80;
      listen [::]:80;
      root /var/www/redcap;
      index.php;
      server_name redcap.local; // change it with the real host name for your RC
      location / {
              try_files $uri $uri/ =404;
      }

}

Now, copy the file to create the 2nd server block sudo cp /etc/nginx/sites-available/grafana /etc/nginx/sites-available/grafana

And edit it sudo nano /etc/nginx/sites-available/grafana

server {

      listen 80;
      listen [::]:80;
      root /var/www/grafana;
      index.php;
      server_name grafana.local; // change it with the real host name for your GF
      location / {
              try_files $uri $uri/ =404;
      }

}

- Enable server blocks and restart nginx Create links between files sudo ln -s /etc/nginx/sites-available/redcap /etc/nginx/sites-enabled/ sudo ln -s /etc/nginx/sites-available/grafana /etc/nginx/sites-enabled/

Check if there is no syntax errors in any created files sudo nginx -t

If there is no error, you can restart nginx server sudo systemctl restart nginx

3. MariaDB install Basic install of MariaDB sudo apt update sudo apt install mariadb-server

You still need to configure user, rights and server configuration but this will not be described in this document. 4. PHP processor Note: `x` should be replaced with the correct PHP version Nginx need a php processor to be able to deliver dynamic content. sudo apt-get install php-fpm php-mysql

Open the php.ini for fpm Sudo nano etc/php/7.x/fpm/php.ini`

Comment out the line with `cgi.fix_pathinfo` and set it to 0 cgi.fix_pathinfo=0

Then, we can restart the PHP processor with sudo systemctl restart php7.x-fpm.service

We have to specify the php processor to be used for each server blocks Open both (RC and GF) SB files sudo nano /etc/nginx/sites-available/<name>

And add these lines location ~ \.php$ {

  include snippets/fastcgi-php.conf;
  fastcgi_pass unix:/run/php/php7.x-fpm.sock;

}

location ~ /\.ht {

  deny all;

}

Check the nginx configuration sudo nginx -t

If no error, reaload it systemctl systemctl reload nginx

If you want more information on SB directive, please refer to the official nginx documentation. Both server block php page should be accessible and rendered correctly. 5. REDCap and Grafana You can replace your example index.php files with RC and GF installation files. For RC and GF installation, please refer to the official documentation. Note that is possible that some dependencies may be missing for RC and GF. See SOP REDCap and SOP Grafana

Ressources

Credentials
server-block-setup.1640595177.txt.gz · Last modified: 2021/12/27 09:52 by arnaud_poletto