aboutsummaryrefslogtreecommitdiffhomepage
path: root/doc/md/Server-configuration.md
diff options
context:
space:
mode:
Diffstat (limited to 'doc/md/Server-configuration.md')
-rw-r--r--doc/md/Server-configuration.md582
1 files changed, 278 insertions, 304 deletions
diff --git a/doc/md/Server-configuration.md b/doc/md/Server-configuration.md
index f9ea2ed2..5c45942c 100644
--- a/doc/md/Server-configuration.md
+++ b/doc/md/Server-configuration.md
@@ -1,17 +1,29 @@
1# Server configuration
1 2
2- [Prerequisites](#prerequisistes)
3- [Apache](#apache)
4- [Nginx](#nginx)
5- [Proxies](#proxies)
6- [See also](#see-also)
7 3
8## Prerequisites
9### Shaarli
10 4
11- A web server and PHP interpreter module/service have been installed. 5## Requirements
12- You have write access to the Shaarli installation directory. 6
13- The correct read/write permissions have been granted to the web server user and group. 7### Operating system and web server
14- Your PHP interpreter is compatible with supported PHP versions: 8
9Shaarli can be hosted on dedicated/virtual servers, or shared hosting. The smallest DigitalOcean VPS (Droplet with 1 CPU, 1 GiB RAM and 25 GiB SSD) costs about $5/month and will run any Shaarli installation without problems.
10
11You need write access to the Shaarli installation directory - you should have received instructions from your hosting provider on how to connect to the server using SSH (or FTP for shared hosts).
12
13Examples in this documentation are given for [Debian](https://www.debian.org/), a GNU/Linux distribution widely used in server environments. Please adapt them to your specific Linux distribution.
14
15### Network and domain name
16
17Try to host the server in a region that is geographically close to your users.
18
19A domain name ([DNS record](https://opensource.com/article/17/4/introduction-domain-name-system-dns)) pointing to the server's public IP address is required to obtain a SSL/TLS certificate and setup HTTPS to secure client traffic to your Shaarli instance.
20
21You can obtain a domain name from a [registrar](https://en.wikipedia.org/wiki/Domain_name_registrar) ([1](https://www.ovh.co.uk/domains), [2](https://www.gandi.net/en/domain)), or from free subdomain providers ([1](https://freedns.afraid.org/)). If you don't have a domain name, please set up a private domain name ([FQDN](ttps://en.wikipedia.org/wiki/Fully_qualified_domain_name) in your clients' [hosts files](https://en.wikipedia.org/wiki/Hosts_(file)) to access the server (direct access by IP address can result in unexpected behavior).
22
23
24### PHP
25
26Supported PHP versions:
15 27
16Version | Status | Shaarli compatibility 28Version | Status | Shaarli compatibility
17:---:|:---:|:---: 29:---:|:---:|:---:
@@ -23,7 +35,7 @@ Version | Status | Shaarli compatibility
235.4 | EOL: 2015-09-14 | Yes (up to Shaarli 0.8.x) 355.4 | EOL: 2015-09-14 | Yes (up to Shaarli 0.8.x)
245.3 | EOL: 2014-08-14 | Yes (up to Shaarli 0.8.x) 365.3 | EOL: 2014-08-14 | Yes (up to Shaarli 0.8.x)
25 37
26- The following PHP extensions are installed on the server: 38Required PHP extensions:
27 39
28Extension | Required? | Usage 40Extension | Required? | Usage
29---|:---:|--- 41---|:---:|---
@@ -34,60 +46,108 @@ Extension | Required? | Usage
34[`php-intl`](http://php.net/manual/en/book.intl.php) | optional | localized text sorting (e.g. `e->è->f`) 46[`php-intl`](http://php.net/manual/en/book.intl.php) | optional | localized text sorting (e.g. `e->è->f`)
35[`php-curl`](http://php.net/manual/en/book.curl.php) | optional | using cURL for fetching webpages and thumbnails in a more robust way 47[`php-curl`](http://php.net/manual/en/book.curl.php) | optional | using cURL for fetching webpages and thumbnails in a more robust way
36[`php-gettext`](http://php.net/manual/en/book.gettext.php) | optional | Use the translation system in gettext mode (faster) 48[`php-gettext`](http://php.net/manual/en/book.gettext.php) | optional | Use the translation system in gettext mode (faster)
37--------------------------------------------------------------------------------
38 49
39### SSL/TLS configuration 50Some [plugins](Plugins.md) may require additional configuration.
51
52
53## SSL/TLS (HTTPS)
40 54
41To setup HTTPS / SSL on your webserver (recommended), you must generate a public/private **key pair** and a **certificate**, and install, configure and activate the appropriate **webserver SSL extension**. 55We recommend setting up [HTTPS](https://en.wikipedia.org/wiki/HTTPS) on your webserver for secure communication between clients and the server.
42 56
43#### Let's Encrypt 57For public-facing web servers this can be done using free SSL/TLS certificates from [Let's Encrypt](https://en.wikipedia.org/wiki/Let's_Encrypt), a non-profit certificate authority provididing free certificates.
44 58
45[Let's Encrypt](https://en.wikipedia.org/wiki/Let%27s_Encrypt) is a certificate authority that provides free TLS/X.509 certificates via an automated process. 59 - [How to secure Apache with Let's Encrypt](https://www.digitalocean.com/community/tutorials/how-to-secure-apache-with-let-s-encrypt-on-debian-10)
60 - [How to secure Nginx with Let's Encrypt](https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-debian-10)
61 - [How To Use Certbot Standalone Mode to Retrieve Let's Encrypt SSL Certificates](https://www.digitalocean.com/community/tutorials/how-to-use-certbot-standalone-mode-to-retrieve-let-s-encrypt-ssl-certificates-on-debian-10).
46 62
47 * Install `certbot` using the appropriate method described on https://certbot.eff.org/. 63In short:
48
49Location of the `certbot` program and template configuration files may vary depending on which installation method was used. Change the file paths below accordingly. Here is an easy way to create a signed certificate using `certbot`, it assumes `certbot` was installed through APT on a Debian-based distribution:
50 64
51 * Stop the apache2/nginx service. 65```bash
52 * Run `certbot --agree-tos --standalone --preferred-challenges tls-sni --email "youremail@example.com" --domain yourdomain.example.com` 66# install certbot
53 * For the Apache webserver, copy `/usr/lib/python2.7/dist-packages/certbot_apache/options-ssl-apache.conf` to `/etc/letsencrypt/options-ssl-apache.conf` (paths may vary depending on installation method) 67sudo apt install certbot
54 * For Nginx: TODO
55 * Setup your webserver as described below
56 * Restart the apache2/nginx service.
57 68
58#### Self-signed certificates 69# stop your webserver if you already have one running
70# certbot in standalone mode needs to bind to port 80 (only needed on initial generation)
71sudo systemctl stop apache2
72sudo systemctl stop nginx
59 73
60If you don't want to request a certificate from Let's Encrypt, or are unable to (for example, webserver on a LAN, or domain name not registered in the public DNS system), you can generate a self-signed certificate. This certificate will trigger security warnings in web browsers, unless you add it to the browser's SSL store manually. 74# generate initial certificates - Let's Encrypt ACME servers must be able to access your server!
75# (DNS records must be correctly pointing to it, firewall/NAT on port 80/443 must be open)
76sudo certbot certonly --standalone --noninteractive --agree-tos --email "admin@shaarli.mydomain.org" -d shaarli.mydomain.org
77# this will generate a private key and certificate at /etc/letsencrypt/live/shaarli.mydomain.org/{privkey,fullchain}.pem
61 78
62* Apache: run `make-ssl-cert generate-default-snakeoil --force-overwrite` 79# restart the web server
63* Nginx: TODO 80sudo systemctl start apache2
81sudo systemctl start nginx
82```
83
84If you don't want to rely on a certificate authority, or the server can only be accessed from your own network, you can also generate self-signed certificates. Not that this will generate security warnings in web browsers/clients trying to access Shaarli:
85
86- [How To Create a Self-Signed SSL Certificate for Apache](https://www.digitalocean.com/community/tutorials/how-to-create-a-self-signed-ssl-certificate-for-apache-on-debian-10)
87- [How To Create a Self-Signed SSL Certificate for Nginx](https://www.digitalocean.com/community/tutorials/how-to-create-a-self-signed-ssl-certificate-for-nginx-on-debian-10)
64 88
65-------------------------------------------------------------------------------- 89--------------------------------------------------------------------------------
66 90
67## Apache 91## Examples
92
93The following examples assume a Debian-based operating system is installed. On other distributions you may have to adapt details such as package installation procedures, configuration file locations, and webserver username/group (`www-data` or `httpd` are common values).
94
95In these examples we assume the document root for your web server/virtualhost is at `/var/www/shaarli.mydomain.org/`:
96
97```bash
98sudo mkdir -p /var/www/shaarli.mydomain.org/
99```
100
101You can install Shaarli at the root of your virtualhost, or in a subdirectory as well. See [Directory structure](Directory-structure)
102
68 103
69Here is a basic configuration example for the Apache web server with `mod_php`. 104### Apache
70 105
71In `/etc/apache2/sites-available/shaarli.conf`: 106```bash
107# Install apache + mod_php and PHP modules
108sudo apt update
109sudo apt install apache2 libapache2-mod-php php-json php-mbstring php-gd php-intl php-curl php-gettext
110
111# Edit the virtualhost configuration file with your favorite editor
112sudo nano /etc/apache2/sites-available/shaarli.mydomain.org.conf
113```
72 114
73```apache 115```apache
116<VirtualHost *:80>
117 ServerName shaarli.mydomain.org
118 DocumentRoot /var/www/shaarli.mydomain.org/
119
120 # Log level. Possible values include: debug, info, notice, warn, error, crit, alert, emerg.
121 LogLevel warn
122 # Log file locations
123 ErrorLog /var/log/apache2/error.log
124 CustomLog /var/log/apache2/access.log combined
125
126 # Redirect HTTP requests to HTTPS
127 RewriteEngine on
128 RewriteRule ^.well-known/acme-challenge/ - [L]
129 # except for Let's Encrypt ACME challenge requests
130 RewriteCond %{HTTP_HOST} =shaarli.mydomain.org
131 RewriteRule ^ https://shaarli.mydomain.org%{REQUEST_URI} [END,NE,R=permanent]
132</VirtualHost>
133
74<VirtualHost *:443> 134<VirtualHost *:443>
75 ServerName shaarli.my-domain.org 135 ServerName shaarli.mydomain.org
76 DocumentRoot /absolute/path/to/shaarli/ 136 DocumentRoot /var/www/shaarli.mydomain.org/
77 137
78 # Logging 138 # Log level. Possible values include: debug, info, notice, warn, error, crit, alert, emerg.
79 # Possible values include: debug, info, notice, warn, error, crit, alert, emerg.
80 LogLevel warn 139 LogLevel warn
81 ErrorLog /var/log/apache2/shaarli-error.log 140 # Log file locations
82 CustomLog /var/log/apache2/shaarli-access.log combined 141 ErrorLog /var/log/apache2/error.log
142 CustomLog /var/log/apache2/access.log combined
83 143
84 # Let's Encrypt SSL configuration (recommended) 144 # SSL/TLS configuration (for Let's Encrypt certificates)
85 SSLEngine on 145 SSLEngine on
86 SSLCertificateFile /etc/letsencrypt/live/yourdomain.example.com/fullchain.pem 146 SSLCertificateFile /etc/letsencrypt/live/shaarli.mydomain.org/fullchain.pem
87 SSLCertificateKeyFile /etc/letsencrypt/live/yourdomain.example.com/privkey.pem 147 SSLCertificateKeyFile /etc/letsencrypt/live/shaarli.mydomain.org/privkey.pem
88 Include /etc/letsencrypt/options-ssl-apache.conf 148 Include /etc/letsencrypt/options-ssl-apache.conf
89 149
90 # Self-signed SSL cert configuration 150 # SSL/TLS configuration (for self-signed certificates)
91 #SSLEngine on 151 #SSLEngine on
92 #SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem 152 #SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
93 #SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key 153 #SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
@@ -98,345 +158,259 @@ In `/etc/apache2/sites-available/shaarli.conf`:
98 #php_value error_reporting 2147483647 158 #php_value error_reporting 2147483647
99 #php_value error_log /var/log/apache2/shaarli-php-error.log 159 #php_value error_log /var/log/apache2/shaarli-php-error.log
100 160
101 <Directory /absolute/path/to/shaarli/> 161 <Directory /var/www/shaarli.mydomain.org/>
102 #Required for .htaccess support 162 # Required for .htaccess support
103 AllowOverride All 163 AllowOverride All
104 Order allow,deny 164 Order allow,deny
105 Allow from all 165 Allow from all
106
107 Options Indexes FollowSymLinks MultiViews #TODO is Indexes/Multiviews required?
108
109 # Optional - required for playvideos plugin
110 #Header set Content-Security-Policy "script-src 'self' 'unsafe-inline' https://www.youtube.com https://s.ytimg.com 'unsafe-eval'"
111 </Directory> 166 </Directory>
112 167
113</VirtualHost> 168 <LocationMatch "/\.">
114``` 169 # Prevent accessing dotfiles
115 170 RedirectMatch 404 ".*"
116Enable this configuration with `sudo a2ensite shaarli` 171 </LocationMatch>
117
118_Note: If you use Apache 2.2 or lower, you need [mod_version](https://httpd.apache.org/docs/current/mod/mod_version.html) to be installed and enabled._
119 172
120_Note: Apache module `mod_rewrite` must be enabled to use the REST API._ 173 <LocationMatch "\.(?:ico|css|js|gif|jpe?g|png)$">
174 # allow client-side caching of static files
175 Header set Cache-Control "max-age=2628000, public, must-revalidate, proxy-revalidate"
176 </LocationMatch>
121 177
178 # serve the Shaarli favicon from its custom location
179 Alias favicon.ico /var/www/shaarli.mydomain.org/images/favicon.ico
122 180
123## Nginx 181</VirtualHost>
182```
124 183
125Here is a basic configuration example for the Nginx web server, using the [php-fpm](http://php-fpm.org) PHP FastCGI Process Manager, and Nginx's [FastCGI](https://en.wikipedia.org/wiki/FastCGI) module. 184```bash
185# Enable the virtualhost
186sudo a2ensite shaarli
126 187
127<!--- TODO refactor everything below this point ---> 188# mod_ssl must be enabled to use TLS/SSL certificates
189# https://httpd.apache.org/docs/current/mod/mod_ssl.html
190sudo a2enmod ssl
128 191
129### Common setup 192# mod_rewrite must be enabled to use the REST API
130Once Nginx and PHP-FPM are installed, we need to ensure: 193# https://httpd.apache.org/docs/current/mod/mod_rewrite.html
194sudo a2enmod rewrite
131 195
132- Nginx and PHP-FPM are running using the _same user and group_ 196# mod_version must only be enabled if you use Apache 2.2 or lower
133- both these user and group have 197# https://httpd.apache.org/docs/current/mod/mod_version.html
134 - `read` permissions for Shaarli resources 198# sudo a2enmod version
135 - `execute` permissions for Shaarli directories _AND_ their parent directories
136 199
137On a production server: 200# restart the apache service
201systemctl restart apache
202```
138 203
139- `user:group` will likely be `http:http`, `www:www` or `www-data:www-data` 204See [How to install the Apache web server](https://www.digitalocean.com/community/tutorials/how-to-install-the-apache-web-server-on-debian-10) for a complete guide.
140- files will be located under `/var/www`, `/var/http` or `/usr/share/nginx`
141 205
142On a development server: 206### Nginx
143 207
144- files may be located in a user's home directory 208Guide on setting up the Nginx web server: [How to install the Nginx web server](https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-debian-10)
145- in this case, make sure both Nginx and PHP-FPM are running as the local user/group!
146 209
147For all following configuration examples, this user/group pair will be used: 210You will also need to install the [PHP-FPM](http://php-fpm.org) interpreter as detailed [here](https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mariadb-php-lemp-stack-on-debian-10#step-3-%E2%80%94-installing-php-for-processing). Nginx and PHP-FPM must be running using the same user and group, here we assume the user/group to be `www-data:www-data` but this may vary depending on your Linux distribution.
148 211
149- `user:group = john:users`,
150 212
151which corresponds to the following service configuration: 213```bash
214# install nginx and php-fpm
215sudo apt update
216sudo apt install nginx php-fpm
152 217
153```ini 218# Edit the virtualhost configuration file with your favorite editor
154; /etc/php/php-fpm.conf 219sudo nano /etc/nginx/sites-available/shaarli.mydomain.org
155user = john
156group = users
157
158[...]
159listen.owner = john
160listen.group = users
161``` 220```
162 221
163```nginx 222```nginx
164# /etc/nginx/nginx.conf 223server {
165user john users; 224 listen 80;
225 server_name shaarli.mydomain.org;
166 226
167http { 227 # redirect all plain HTTP requests to HTTPS
168 [...] 228 return 301 https://shaarli.mydomain.org$request_uri;
169} 229}
170```
171 230
172### (Optional) Increase the maximum file upload size 231server {
173Some bookmark dumps generated by web browsers can be _huge_ due to the presence of Base64-encoded images and favicons, as well as extra verbosity when nesting links in (sub-)folders. 232 listen 443 ssl;
233 server_name shaarli.mydomain.org;
234 root /var/www/shaarli.mydomain.org;
174 235
175To increase upload size, you will need to modify both nginx and PHP configuration: 236 # log file locations
176 237 # combined log format prepends the virtualhost/domain name to log entries
177```nginx 238 access_log /var/log/nginx/access.log combined;
178# /etc/nginx/nginx.conf 239 error_log /var/log/nginx/error.log;
179
180http {
181 [...]
182
183 client_max_body_size 10m;
184
185 [...]
186}
187```
188
189```ini
190# /etc/php/<PHP_VERSION>/fpm/php.ini
191
192[...]
193post_max_size = 10M
194[...]
195upload_max_filesize = 10M
196```
197 240
198### Minimal 241 # paths to private key and certificates for SSL/TLS
199_WARNING: Use for development only!_ 242 ssl_certificate /etc/ssl/shaarli.mydomain.org.crt;
243 ssl_certificate_key /etc/ssl/private/shaarli.mydomain.org.key;
200 244
201```nginx 245 # increase the maximum file upload size if needed: by default nginx limits file upload to 1MB (413 Entity Too Large error)
202user john users; 246 client_max_body_size 100m;
203worker_processes 1;
204events {
205 worker_connections 1024;
206}
207 247
208http { 248 # relative path to shaarli from the root of the webserver
209 include mime.types; 249 location / {
210 default_type application/octet-stream; 250 # default index file when no file URI is requested
211 keepalive_timeout 20; 251 index index.php;
212 252 try_files $uri /index.php$is_args$args;
213 index index.html index.php;
214
215 server {
216 listen 80;
217 server_name localhost;
218 root /home/john/web;
219
220 access_log /var/log/nginx/access.log;
221 error_log /var/log/nginx/error.log;
222
223 location /shaarli/ {
224 try_files $uri /shaarli/index.php$is_args$args;
225 access_log /var/log/nginx/shaarli.access.log;
226 error_log /var/log/nginx/shaarli.error.log;
227 }
228
229 location ~ (index)\.php$ {
230 try_files $uri =404;
231 fastcgi_split_path_info ^(.+\.php)(/.+)$;
232 fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
233 fastcgi_index index.php;
234 include fastcgi.conf;
235 }
236 } 253 }
237}
238```
239 254
240### Modular 255 location ~ (index)\.php$ {
241The previous setup is sufficient for development purposes, but has several major caveats: 256 try_files $uri =404;
257 # slim API - split URL path into (script_filename, path_info)
258 fastcgi_split_path_info ^(.+\.php)(/.+)$;
259 # pass PHP requests to PHP-FPM
260 fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
261 fastcgi_index index.php;
262 include fastcgi.conf;
263 }
242 264
243- every content that does not match the PHP rule will be sent to client browsers: 265 location ~ \.php$ {
244 - dotfiles - in our case, `.htaccess` 266 # deny access to all other PHP scripts
245 - temporary files, e.g. Vim or Emacs files: `index.php~` 267 # disable this if you host other PHP applications on the same virtualhost
246- asset / static resource caching is not optimized 268 deny all;
247- if serving several PHP sites, there will be a lot of duplication: `location /shaarli/`, `location /mysite/`, etc. 269 }
248 270
249To solve this, we will split Nginx configuration in several parts, that will be included when needed: 271 location ~ /\. {
272 # deny access to dotfiles
273 deny all;
274 }
250 275
251```nginx 276 location ~ ~$ {
252# /etc/nginx/deny.conf 277 # deny access to temp editor files, e.g. "script.php~"
253location ~ /\. { 278 deny all;
254 # deny access to dotfiles 279 }
255 access_log off;
256 log_not_found off;
257 deny all;
258}
259 280
260location ~ ~$ { 281 location = /favicon.ico {
261 # deny access to temp editor files, e.g. "script.php~" 282 # serve the Shaarli favicon from its custom location
262 access_log off; 283 alias /var/www/shaarli/images/favicon.ico;
263 log_not_found off; 284 }
264 deny all;
265}
266```
267 285
268```nginx 286 # allow client-side caching of static files
269# /etc/nginx/php.conf 287 location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
270location ~ (index)\.php$ { 288 expires max;
271 # Slim - split URL path into (script_filename, path_info) 289 add_header Cache-Control "public, must-revalidate, proxy-revalidate";
272 try_files $uri =404; 290 # HTTP 1.0 compatibility
273 fastcgi_split_path_info ^(.+\.php)(/.+)$; 291 add_header Pragma public;
274 292 }
275 # filter and proxy PHP requests to PHP-FPM
276 fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
277 fastcgi_index index.php;
278 include fastcgi.conf;
279}
280 293
281location ~ \.php$ {
282 # deny access to all other PHP scripts
283 deny all;
284} 294}
285``` 295```
286 296
287```nginx 297```bash
288# /etc/nginx/static_assets.conf 298# enable the configuration/virtualhost
289location ~* \.(?:ico|css|js|gif|jpe?g|png)$ { 299sudo ln -s /etc/nginx/sites-available/shaarli.mydomain.org /etc/nginx/sites-enabled/shaarli.mydomain.org
290 expires max; 300# reload nginx configuration
291 add_header Pragma public; 301sudo systemctl reload nginx
292 add_header Cache-Control "public, must-revalidate, proxy-revalidate";
293}
294``` 302```
295 303
296```nginx
297# /etc/nginx/nginx.conf
298[...]
299
300http {
301 [...]
302
303 root /home/john/web;
304 access_log /var/log/nginx/access.log;
305 error_log /var/log/nginx/error.log;
306 304
307 server { 305## Reverse proxies
308 # virtual host for a first domain
309 listen 80;
310 server_name my.first.domain.org;
311 306
312 location /shaarli/ { 307If Shaarli is hosted on a server behind a [reverse proxy](https://en.wikipedia.org/wiki/Reverse_proxy) (i.e. there is a proxy server between clients and the web server hosting Shaarli), configure it accordingly. See [Reverse proxy](Reverse-proxy.md) configuration.
313 # Slim - rewrite URLs
314 try_files $uri /shaarli/index.php$is_args$args;
315 308
316 access_log /var/log/nginx/shaarli.access.log;
317 error_log /var/log/nginx/shaarli.error.log;
318 }
319 309
320 location = /shaarli/favicon.ico {
321 # serve the Shaarli favicon from its custom location
322 alias /var/www/shaarli/images/favicon.ico;
323 }
324 310
325 include deny.conf; 311## Allow import of large browser bookmarks export
326 include static_assets.conf;
327 include php.conf;
328 }
329 312
330 server { 313Web browser bookmark exports can be large due to the presence of base64-encoded images and favicons/long subfolder names. Edit the PHP configuration file.
331 # virtual host for a second domain
332 listen 80;
333 server_name second.domain.com;
334 314
335 location /minigal/ { 315- Apache: `/etc/php/<PHP_VERSION>/apache2/php.ini`
336 access_log /var/log/nginx/minigal.access.log; 316- Nginx + PHP-FPM: `/etc/php/<PHP_VERSION>/fpm/php.ini` (in addition to `client_max_body_size` in the [Nginx configuration](#nginx))
337 error_log /var/log/nginx/minigal.error.log;
338 }
339 317
340 include deny.conf; 318```ini
341 include static_assets.conf;
342 include php.conf;
343 }
344}
345```
346
347### Redirect HTTP to HTTPS
348Assuming you have generated a (self-signed) key and certificate, and they are
349located under `/home/john/ssl/localhost.{key,crt}`, it is pretty straightforward
350to set an HTTP (:80) to HTTPS (:443) redirection to force SSL/TLS usage.
351
352```nginx
353# /etc/nginx/nginx.conf
354[...] 319[...]
320# (optional) increase the maximum file upload size:
321post_max_size = 100M
322[...]
323# (optional) increase the maximum file upload size:
324upload_max_filesize = 100M
325```
355 326
356http { 327To verify PHP settings currently set on the server, create a `phpinfo.php` in your webserver's document root
357 [...]
358
359 index index.html index.php;
360
361 root /home/john/web;
362 access_log /var/log/nginx/access.log;
363 error_log /var/log/nginx/error.log;
364
365 server {
366 listen 80;
367 server_name localhost;
368 328
369 return 301 https://localhost$request_uri; 329```bash
370 } 330# example
331echo '<?php phpinfo(); ?>' | sudo tee /var/www/shaarli.mydomain.org/phpinfo.php
332#give read-only access to this file to the webserver user
333sudo chown www-data:root /var/www/shaarli.mydomain.org/phpinfo.php
334sudo chmod 0400 /var/www/shaarli.mydomain.org/phpinfo.php
335```
371 336
372 server { 337Access the file from a web browser (eg. <https://shaarli.mydomain.org/phpinfo.php> and look at the _Loaded Configuration File_ and _Scan this dir for additional .ini files_ entries
373 listen 443 ssl;
374 server_name localhost;
375 338
376 ssl_certificate /home/john/ssl/localhost.crt; 339It is recommended to remove the `phpinfo.php` when no longer needed as it publicly discloses details about your webserver configuration.
377 ssl_certificate_key /home/john/ssl/localhost.key;
378 340
379 location /shaarli/ {
380 # Slim - rewrite URLs
381 try_files $uri /index.php$is_args$args;
382 341
383 access_log /var/log/nginx/shaarli.access.log; 342## Robots and crawlers
384 error_log /var/log/nginx/shaarli.error.log;
385 }
386 343
387 location = /shaarli/favicon.ico { 344To opt-out of indexing your Shaarli instance by search engines, create a `robots.txt` file at the root of your virtualhost:
388 # serve the Shaarli favicon from its custom location
389 alias /var/www/shaarli/images/favicon.ico;
390 }
391 345
392 include deny.conf; 346```
393 include static_assets.conf; 347User-agent: *
394 include php.conf; 348Disallow: /
395 }
396}
397``` 349```
398 350
399## Proxies 351By default Shaarli already disallows indexing of your local copy of the documentation by default, using `<meta name="robots">` HTML tags. Your Shaarli instance may still be indexed by various robots on the public Internet, that do not respect this header or the robots standard.
400
401If Shaarli is served behind a proxy (i.e. there is a proxy server between clients and the web server hosting Shaarli), please refer to the proxy server documentation for proper configuration. In particular, you have to ensure that the following server variables are properly set:
402 352
403- `X-Forwarded-Proto` 353- [Robots exclusion standard](https://en.wikipedia.org/wiki/Robots_exclusion_standard)
404- `X-Forwarded-Host` 354- [Introduction to robots.txt](https://support.google.com/webmasters/answer/6062608?hl=en)
405- `X-Forwarded-For` 355- [Robots meta tag, data-nosnippet, and X-Robots-Tag specifications](https://developers.google.com/search/reference/robots_meta_tag)
356- [About robots.txt](http://www.robotstxt.org)
357- [About the robots META tag](https://www.robotstxt.org/meta.html)
406 358
407In you [Shaarli configuration](Shaarli-configuration) `data/config.json.php`, add the public IP of your proxy under `security.trusted_proxies`.
408 359
409See also [proxy-related](https://github.com/shaarli/Shaarli/issues?utf8=%E2%9C%93&q=label%3Aproxy+) issues. 360## Fail2ban
410 361
411## Robots and crawlers 362[fail2ban](http://www.fail2ban.org/wiki/index.php/Main_Page) is an intrusion prevention framework that reads server (Apache, SSH, etc.) and uses `iptables` profiles to block brute-force attempts. You need to create a filter to detect shaarli login failures in logs, and a jail configuation to configure the behavior when failed login attempts are detected:
412 363
413Shaarli disallows indexing and crawling of your local documentation pages by search engines, using `<meta name="robots">` HTML tags. 364```ini
414Your Shaarli instance and other pages you host may still be indexed by various robots on the public Internet. 365# /etc/fail2ban/filter.d/shaarli-auth.conf
415You may want to setup a robots.txt file or other crawler control mechanism on your server. 366[INCLUDES]
416See [[1]](https://en.wikipedia.org/wiki/Robots_exclusion_standard), [[2]](https://support.google.com/webmasters/answer/6062608?hl=en) and [[3]](https://developers.google.com/search/reference/robots_meta_tag) 367before = common.conf
417 368[Definition]
418## See also 369failregex = \s-\s<HOST>\s-\sLogin failed for user.*$
370ignoreregex =
371```
419 372
420 * [Server security](Server-security.md) 373```ini
374# /etc/fail2ban/jail.local
375[shaarli-auth]
376enabled = true
377port = https,http
378filter = shaarli-auth
379logpath = /var/www/shaarli.mydomain.org/data/log.txt
380# allow 3 login attempts per IP address
381# (over a period specified by findtime = in /etc/fail2ban/jail.conf)
382maxretry = 3
383# permanently ban the IP address after reaching the limit
384bantime = -1
385```
421 386
422#### Webservers 387#### References
423 388
424- [Apache/PHP - error log per VirtualHost](http://stackoverflow.com/q/176) (StackOverflow) 389- [Apache/PHP - error log per VirtualHost - StackOverflow](http://stackoverflow.com/q/176)
425- [Apache - PHP: php_value vs php_admin_value and the use of php_flag explained](https://ma.ttias.be/php-php_value-vs-php_admin_value-and-the-use-of-php_flag-explained/) 390- [Apache - PHP: php_value vs php_admin_value and the use of php_flag explained](https://ma.ttias.be/php-php_value-vs-php_admin_value-and-the-use-of-php_flag-explained/)
426- [Server-side TLS (Apache)](https://wiki.mozilla.org/Security/Server_Side_TLS#Apache) (Mozilla) 391- [Server-side TLS (Apache) - Mozilla](https://wiki.mozilla.org/Security/Server_Side_TLS#Apache)
427- [Nginx Beginner's guide](http://nginx.org/en/docs/beginners_guide.html) 392- [Nginx Beginner's guide](http://nginx.org/en/docs/beginners_guide.html)
428- [Nginx ngx_http_fastcgi_module](http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html) 393- [Nginx ngx_http_fastcgi_module](http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html)
429- [Nginx Pitfalls](http://wiki.nginx.org/Pitfalls) 394- [Nginx Pitfalls](http://wiki.nginx.org/Pitfalls)
430- [Nginx PHP configuration examples](http://kbeezie.com/nginx-configuration-examples/) (Karl Blessing) 395- [Nginx PHP configuration examples - Karl Blessing](http://kbeezie.com/nginx-configuration-examples/)
431- [Server-side TLS (Nginx)](https://wiki.mozilla.org/Security/Server_Side_TLS#Nginx) (Mozilla) 396- [Apache 2.4 documentation](https://httpd.apache.org/docs/2.4/)
397- [Apache mod_proxy](https://httpd.apache.org/docs/2.4/mod/mod_proxy.html)
398- [Apache Reverse Proxy Request Headers](https://httpd.apache.org/docs/2.4/mod/mod_proxy.html#x-headers)
399- [HAProxy documentation](https://cbonte.github.io/haproxy-dconv/)
400- [Nginx documentation](https://nginx.org/en/docs/)
401- [`X-Forwarded-Proto`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Proto)
402- [`X-Forwarded-Host`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Host)
403- [`X-Forwarded-For`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For)
404- [Server-side TLS (Nginx) - Mozilla](https://wiki.mozilla.org/Security/Server_Side_TLS#Nginx)
432- [How to Create Self-Signed SSL Certificates with OpenSSL](http://www.xenocafe.com/tutorials/linux/centos/openssl/self_signed_certificates/index.php) 405- [How to Create Self-Signed SSL Certificates with OpenSSL](http://www.xenocafe.com/tutorials/linux/centos/openssl/self_signed_certificates/index.php)
433- [How do I create my own Certificate Authority?](https://workaround.org/certificate-authority) 406- [How do I create my own Certificate Authority?](https://workaround.org/certificate-authority)
434
435#### PHP
436
437- [Travis configuration](https://github.com/shaarli/Shaarli/blob/master/.travis.yml) 407- [Travis configuration](https://github.com/shaarli/Shaarli/blob/master/.travis.yml)
438- [PHP: Supported versions](http://php.net/supported-versions.php) 408- [PHP: Supported versions](http://php.net/supported-versions.php)
439- [PHP: Unsupported versions](http://php.net/eol.php) _(EOL - End Of Life)_ 409- [PHP: Unsupported versions (EOL/End-of-life)](http://php.net/eol.php)
440- [PHP 7 Changelog](http://php.net/ChangeLog-7.php) 410- [PHP 7 Changelog](http://php.net/ChangeLog-7.php)
441- [PHP 5 Changelog](http://php.net/ChangeLog-5.php) 411- [PHP 5 Changelog](http://php.net/ChangeLog-5.php)
442- [PHP: Bugs](https://bugs.php.net/) 412- [PHP: Bugs](https://bugs.php.net/)
413- [Transport Layer Security](https://en.wikipedia.org/wiki/Transport_Layer_Security)
414- Hosting providers: [DigitalOcean](https://www.digitalocean.com/) ([1](https://www.digitalocean.com/docs/droplets/overview/), [2](https://www.digitalocean.com/pricing/), [3](https://www.digitalocean.com/docs/droplets/how-to/create/), [How to Add SSH Keys to Droplets](https://www.digitalocean.com/docs/droplets/how-to/add-ssh-keys/), [4](https://www.digitalocean.com/community/tutorials/initial-server-setup-with-debian-8), [5](https://www.digitalocean.com/community/tutorials/an-introduction-to-securing-your-linux-vps)), [Gandi](https://www.gandi.net/en), [OVH](https://www.ovh.co.uk/), [RackSpace](https://www.rackspace.com/), etc.
415
416