User Tools

Site Tools


server-block-setup

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
server-block-setup [2021/12/27 10:40] arnaud_polettoserver-block-setup [2022/01/10 14:56] (current) – removed arnaud_poletto
Line 1: Line 1:
-====== 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. 
- 
- 
- 
- 
-===== 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. 
-We need to create these directories for each needed sites: 
-<code> 
-sudo mkdir -p /var/www/redcap 
-sudo mkdir -p /var/www/grafana 
-</code> 
- 
-Assign the current user and give him right rights on the created folders (do not use root user): 
-<code> 
-sudo chown -R $USER:$USER /var/www/redcap 
-sudo chown -R $USER:$USER /var/www/grafana 
-sudo chmod -R 755 /var/www 
-</code> 
- 
-Create a test file for each site: 
-<code> 
-nano /var/www/{site}/ index.php 
-</code> 
- 
-Edit each php file with some test content: 
-<code> 
-<?php 
-phpinfo(); 
-</code> 
- 
-Now, create server Block files for each domain. Create the first SB and use the default template.: 
-<code> 
-sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/redcap 
-</code> 
- 
-Edit the new SB: 
-<code> 
-sudo nano /etc/nginx/sites-available/example.com 
-</code> 
- 
-Here is an example of SB file configuration: 
-<code> 
-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; 
-        } 
-} 
-</code> 
- 
-Now, copy the file to create the 2nd server block: 
-<code> 
-sudo cp /etc/nginx/sites-available/grafana /etc/nginx/sites-available/grafana 
-</code> 
- 
-And edit it: 
-<code> 
-sudo nano /etc/nginx/sites-available/grafana 
-</code> 
-<code> 
-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; 
-        } 
-} 
-</code> 
- 
-Create links between files: 
-<code> 
-sudo ln -s /etc/nginx/sites-available/redcap /etc/nginx/sites-enabled/ 
-sudo ln -s /etc/nginx/sites-available/grafana /etc/nginx/sites-enabled/ 
-</code> 
- 
-Check if there is no syntax errors in any created files: 
-<code> 
-sudo nginx -t 
-</code> 
- 
-If there is no error, you can restart nginx server 
-<code> 
-sudo systemctl restart nginx 
-</code> 
- 
-===== MariaDB Setup ===== 
- 
-Then, install MariaDB: 
-<code> 
-sudo apt update 
-sudo apt install mariadb-server 
-</code> 
- 
-You still need to configure users, rights and server configuration but this will not be described in this document. 
- 
- 
- 
- 
-===== PHP processor ===== 
-Note: ''x'' should be replaced with the correct PHP version 
-Nginx need a php processor to be able to deliver dynamic content: 
-<code> 
-sudo apt-get install php-fpm php-mysql 
-</code> 
- 
-Open the php.ini for fpm: 
-<code> 
-sudo nano etc/php/7.x/fpm/php.ini 
-</code> 
- 
-Comment out the line with ''cgi.fix_pathinfo'' and set it to 0: 
-<code> 
-cgi.fix_pathinfo=0 
-</code> 
- 
-Then, we can restart the PHP processor with: 
-<code> 
-sudo systemctl restart php7.x-fpm.service 
-</code> 
- 
-We have to specify the php processor to be used for each server blocks. Open both (RC and GF) SB files: 
-<code> 
-sudo nano /etc/nginx/sites-available/<name> 
-</code> 
- 
-And add these lines: 
-<code> 
-location ~ \.php$ { 
-    include snippets/fastcgi-php.conf; 
-    fastcgi_pass unix:/run/php/php7.x-fpm.sock; 
-} 
- 
-location ~ /\.ht { 
-    deny all; 
-} 
-</code> 
- 
-Check the nginx configuration: 
-<code> 
-sudo nginx -t 
-</code> 
- 
-If no error, reaload it: 
-<code> 
-systemctl systemctl reload nginx 
-</code> 
- 
-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. 
- 
- 
- 
- 
-===== 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. 
- 
- 
- 
- 
-===== Ressources ===== 
- 
-  * Server block install: https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-16-04 
-  * MariaDB install: https://www.digitalocean.com/community/tutorials/how-to-install-mariadb-on-ubuntu-18-04 
-  * PHP processing for nginx (resources in French): https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-20-04-fr 
- 
- 
- 
-DELETEME 
-== Credentials == 
server-block-setup.1640598028.txt.gz · Last modified: 2021/12/27 10:40 by arnaud_poletto