aboutsummaryrefslogblamecommitdiffhomepage
path: root/doc/html/Server-configuration/index.html
blob: beb8cd08c8af614986c5a2568c383dfa69166c4c (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747










































































































































































































































































































































































































































































































































































































































































































































































                                                                                                                                                                                                                                                                                          
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  
  <link rel="shortcut icon" href="../img/favicon.ico">
  <title>Server configuration - Shaarli Documentation</title>
  <link href='https://fonts.googleapis.com/css?family=Lato:400,700|Roboto+Slab:400,700|Inconsolata:400,700' rel='stylesheet' type='text/css'>

  <link rel="stylesheet" href="../css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../css/theme_extra.css" type="text/css" />
  <link rel="stylesheet" href="../css/highlight.css">
  <link href="../github-markdown.css" rel="stylesheet">
  
  <script>
    // Current page data
    var mkdocs_page_name = "Server configuration";
    var mkdocs_page_input_path = "Server-configuration.md";
    var mkdocs_page_url = "/Server-configuration/";
  </script>
  
  <script src="../js/jquery-2.1.1.min.js"></script>
  <script src="../js/modernizr-2.8.3.min.js"></script>
  <script type="text/javascript" src="../js/highlight.pack.js"></script> 
  
</head>

<body class="wy-body-for-nav" role="document">

  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
      <div class="wy-side-nav-search">
        <a href=".." class="icon icon-home"> Shaarli Documentation</a>
        <div role="search">
  <form id ="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
  </form>
</div>
      </div>

      <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
	<ul class="current">
	  
          
            <li class="toctree-l1">
		
    <a class="" href="..">Home</a>
	    </li>
          
            <li class="toctree-l1">
		
    <span class="caption-text">Setup</span>
    <ul class="subnav">
                <li class="">
                    
    <a class="" href="../Download-and-Installation/">Download and Installation</a>
                </li>
                <li class="">
                    
    <a class="" href="../Upgrade-and-migration/">Upgrade and migration</a>
                </li>
                <li class="">
                    
    <a class="" href="../Server-requirements/">Server requirements</a>
                </li>
                <li class=" current">
                    
    <a class="current" href="./">Server configuration</a>
    <ul class="subnav">
            
    <li class="toctree-l3"><a href="#prerequisites">Prerequisites</a></li>
    
        <ul>
        
            <li><a class="toctree-l4" href="#shaarli">Shaarli</a></li>
        
            <li><a class="toctree-l4" href="#https-tls-and-self-signed-certificates">HTTPS, TLS and self-signed certificates</a></li>
        
            <li><a class="toctree-l4" href="#proxies">Proxies</a></li>
        
        </ul>
    

    <li class="toctree-l3"><a href="#apache">Apache</a></li>
    
        <ul>
        
            <li><a class="toctree-l4" href="#minimal">Minimal</a></li>
        
            <li><a class="toctree-l4" href="#debug-log-all-the-things">Debug - Log all the things!</a></li>
        
            <li><a class="toctree-l4" href="#standard-keep-access-and-error-logs">Standard - Keep access and error logs</a></li>
        
            <li><a class="toctree-l4" href="#paranoid-redirect-http-80-to-https-443">Paranoid - Redirect HTTP (:80) to HTTPS (:443)</a></li>
        
            <li><a class="toctree-l4" href="#htaccess">.htaccess</a></li>
        
        </ul>
    

    <li class="toctree-l3"><a href="#lighthttpd">LightHttpd</a></li>
    

    <li class="toctree-l3"><a href="#nginx">Nginx</a></li>
    
        <ul>
        
            <li><a class="toctree-l4" href="#foreword">Foreword</a></li>
        
            <li><a class="toctree-l4" href="#common-setup">Common setup</a></li>
        
            <li><a class="toctree-l4" href="#optional-increase-the-maximum-file-upload-size">(Optional) Increase the maximum file upload size</a></li>
        
            <li><a class="toctree-l4" href="#minimal_1">Minimal</a></li>
        
            <li><a class="toctree-l4" href="#modular">Modular</a></li>
        
            <li><a class="toctree-l4" href="#redirect-http-to-https">Redirect HTTP to HTTPS</a></li>
        
        </ul>
    

    </ul>
                </li>
                <li class="">
                    
    <a class="" href="../Server-security/">Server security</a>
                </li>
                <li class="">
                    
    <a class="" href="../Shaarli-configuration/">Shaarli configuration</a>
                </li>
                <li class="">
                    
    <a class="" href="../Plugins/">Plugins</a>
                </li>
    </ul>
	    </li>
          
            <li class="toctree-l1">
		
    <span class="caption-text">Docker</span>
    <ul class="subnav">
                <li class="">
                    
    <a class="" href="../Docker-101/">Docker 101</a>
                </li>
                <li class="">
                    
    <a class="" href="../Shaarli-images/">Shaarli images</a>
                </li>
                <li class="">
                    
    <a class="" href="../Reverse-proxy-configuration/">Reverse proxy configuration</a>
                </li>
                <li class="">
                    
    <a class="" href="../Docker-resources/">Docker resources</a>
                </li>
    </ul>
	    </li>
          
            <li class="toctree-l1">
		
    <span class="caption-text">Usage</span>
    <ul class="subnav">
                <li class="">
                    
    <a class="" href="../Features/">Features</a>
                </li>
                <li class="">
                    
    <a class="" href="../Bookmarklet/">Bookmarklet</a>
                </li>
                <li class="">
                    
    <a class="" href="../Browsing-and-searching/">Browsing and searching</a>
                </li>
                <li class="">
                    
    <a class="" href="../Firefox-share/">Firefox share</a>
                </li>
                <li class="">
                    
    <a class="" href="../RSS-feeds/">RSS feeds</a>
                </li>
                <li class="">
                    
    <a class="" href="../REST-API/">REST API</a>
                </li>
    </ul>
	    </li>
          
            <li class="toctree-l1">
		
    <span class="caption-text">How To</span>
    <ul class="subnav">
                <li class="">
                    
    <a class="" href="../Backup,-restore,-import-and-export/">Backup, restore, import and export</a>
                </li>
                <li class="">
                    
    <a class="" href="../Copy-an-existing-installation-over-SSH-and-serve-it-locally/">Copy an existing installation over SSH and serve it locally</a>
                </li>
                <li class="">
                    
    <a class="" href="../Create-and-serve-multiple-Shaarlis-(farm)/">Create and serve multiple Shaarlis (farm)</a>
                </li>
                <li class="">
                    
    <a class="" href="../Download-CSS-styles-from-an-OPML-list/">Download CSS styles from an OPML list</a>
                </li>
                <li class="">
                    
    <a class="" href="../Datastore-hacks/">Datastore hacks</a>
                </li>
    </ul>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../Troubleshooting/">Troubleshooting</a>
	    </li>
          
            <li class="toctree-l1">
		
    <span class="caption-text">Development</span>
    <ul class="subnav">
                <li class="">
                    
    <a class="" href="../Development-guidelines/">Development guidelines</a>
                </li>
                <li class="">
                    
    <a class="" href="../Continuous-integration-tools/">Continuous integration tools</a>
                </li>
                <li class="">
                    
    <a class="" href="../GnuPG-signature/">GnuPG signature</a>
                </li>
                <li class="">
                    
    <a class="" href="../Coding-guidelines/">Coding guidelines</a>
                </li>
                <li class="">
                    
    <a class="" href="../Directory-structure/">Directory structure</a>
                </li>
                <li class="">
                    
    <a class="" href="../3rd-party-libraries/">3rd party libraries</a>
                </li>
                <li class="">
                    
    <a class="" href="../Plugin-System/">Plugin System</a>
                </li>
                <li class="">
                    
    <a class="" href="../Release-Shaarli/">Release Shaarli</a>
                </li>
                <li class="">
                    
    <a class="" href="../Versioning-and-Branches/">Versioning and Branches</a>
                </li>
                <li class="">
                    
    <a class="" href="../Security/">Security</a>
                </li>
                <li class="">
                    
    <a class="" href="../Static-analysis/">Static analysis</a>
                </li>
                <li class="">
                    
    <a class="" href="../Theming/">Theming</a>
                </li>
                <li class="">
                    
    <a class="" href="../Unit-tests/">Unit tests</a>
                </li>
    </ul>
	    </li>
          
            <li class="toctree-l1">
		
    <span class="caption-text">About</span>
    <ul class="subnav">
                <li class="">
                    
    <a class="" href="../FAQ/">FAQ</a>
                </li>
                <li class="">
                    
    <a class="" href="../Community-&-Related-software/">Community & Related software</a>
                </li>
    </ul>
	    </li>
          
        </ul>
      </div>
      &nbsp;
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
        <a href="..">Shaarli Documentation</a>
      </nav>

      
      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
    <li><a href="..">Docs</a> &raquo;</li>
    
      
        
          <li>Setup &raquo;</li>
        
      
    
    <li>Server configuration</li>
    <li class="wy-breadcrumbs-aside">
      
        <a href="https://github.com/shaarli/Shaarli/edit/master/docs/Server-configuration.md"
          class="icon icon-github"> Edit on GitHub</a>
      
    </li>
  </ul>
  <hr/>
</div>
          <div role="main">
            <div class="section">
              
                <p><em>Example virtual host configurations for popular web servers</em></p>
<ul>
<li><a href="#apache">Apache</a></li>
<li><a href="#nginx">Nginx</a></li>
</ul>
<h2 id="prerequisites">Prerequisites</h2>
<h3 id="shaarli">Shaarli</h3>
<ul>
<li>Shaarli is installed in a directory readable/writeable by the user</li>
<li>the correct read/write permissions have been granted to the web server <em>user and/or group</em></li>
<li>for HTTPS / SSL:</li>
<li>a key pair (public, private) and a certificate have been generated</li>
<li>the appropriate server SSL extension is installed and active</li>
</ul>
<h3 id="https-tls-and-self-signed-certificates">HTTPS, TLS and self-signed certificates</h3>
<p>Related guides:
<em> <a href="http://www.xenocafe.com/tutorials/linux/centos/openssl/self_signed_certificates/index.php">How to Create Self-Signed SSL Certificates with OpenSSL</a>
</em> <a href="https://workaround.org/certificate-authority">How do I create my own Certificate Authority?</a>
* Generate a self-signed certificate (will trigger browser warnings) with apache2: <code>make-ssl-cert generate-default-snakeoil --force-overwrite</code> will create <code>/etc/ssl/certs/ssl-cert-snakeoil.pem</code> and <code>/etc/ssl/private/ssl-cert-snakeoil.key</code></p>
<h3 id="proxies">Proxies</h3>
<p>If 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:
- <code>X-Forwarded-Proto</code>;
- <code>X-Forwarded-Host</code>;
- <code>X-Forwarded-For</code>.</p>
<p>See also <a href="https://github.com/shaarli/Shaarli/issues?utf8=%E2%9C%93&amp;q=label%3Aproxy+">proxy-related</a> issues.</p>
<h2 id="apache">Apache</h2>
<h3 id="minimal">Minimal</h3>
<pre><code class="apache">&lt;VirtualHost *:80&gt;
    ServerName   shaarli.my-domain.org
    DocumentRoot /absolute/path/to/shaarli/
&lt;/VirtualHost&gt;
</code></pre>

<h3 id="debug-log-all-the-things">Debug - Log all the things!</h3>
<p>This configuration will log both Apache and PHP errors, which may prove useful to identify server configuration errors.</p>
<p>See:
<em> <a href="http://stackoverflow.com/q/176">Apache/PHP - error log per VirtualHost</a> (StackOverflow)
</em> <a href="https://ma.ttias.be/php-php_value-vs-php_admin_value-and-the-use-of-php_flag-explained/">PHP: php_value vs php_admin_value and the use of php_flag explained</a></p>
<pre><code class="apache">&lt;VirtualHost *:80&gt;
    ServerName   shaarli.my-domain.org
    DocumentRoot /absolute/path/to/shaarli/

    LogLevel  warn
    ErrorLog  /var/log/apache2/shaarli-error.log
    CustomLog /var/log/apache2/shaarli-access.log combined

    php_flag  log_errors on
    php_flag  display_errors on
    php_value error_reporting 2147483647
    php_value error_log /var/log/apache2/shaarli-php-error.log
&lt;/VirtualHost&gt;
</code></pre>

<h3 id="standard-keep-access-and-error-logs">Standard - Keep access and error logs</h3>
<pre><code class="apache">&lt;VirtualHost *:80&gt;
    ServerName   shaarli.my-domain.org
    DocumentRoot /absolute/path/to/shaarli/

    LogLevel  warn
    ErrorLog  /var/log/apache2/shaarli-error.log
    CustomLog /var/log/apache2/shaarli-access.log combined
&lt;/VirtualHost&gt;
</code></pre>

<h3 id="paranoid-redirect-http-80-to-https-443">Paranoid - Redirect HTTP (:80) to HTTPS (:443)</h3>
<p>See <a href="https://wiki.mozilla.org/Security/Server_Side_TLS#Apache">Server-side TLS</a> (Mozilla).</p>
<pre><code class="apache">&lt;VirtualHost *:443&gt;
    ServerName   shaarli.my-domain.org
    DocumentRoot /absolute/path/to/shaarli/

    SSLEngine             on
    SSLCertificateFile    /absolute/path/to/the/website/certificate.pem
    SSLCertificateKeyFile /absolute/path/to/the/website/key.key

    &lt;Directory /absolute/path/to/shaarli/&gt;
        AllowOverride All
        Options Indexes FollowSymLinks MultiViews
        Order allow,deny
        allow from all
    &lt;/Directory&gt;

    LogLevel  warn
    ErrorLog  /var/log/apache2/shaarli-error.log
    CustomLog /var/log/apache2/shaarli-access.log combined
&lt;/VirtualHost&gt;
&lt;VirtualHost *:80&gt;
    ServerName   shaarli.my-domain.org
    Redirect 301 / https://shaarli.my-domain.org

    LogLevel  warn
    ErrorLog  /var/log/apache2/shaarli-error.log
    CustomLog /var/log/apache2/shaarli-access.log combined
&lt;/VirtualHost&gt;
</code></pre>

<h3 id="htaccess">.htaccess</h3>
<p>Shaarli use <code>.htaccess</code> Apache files to deny access to files that shouldn't be directly accessed (datastore, config, etc.). You need the directive <code>AllowOverride All</code> in your virtual host configuration for them to work.</p>
<p><strong>Warning</strong>: If you use Apache 2.2 or lower, you need <a href="https://httpd.apache.org/docs/current/mod/mod_version.html">mod_version</a> to be installed and enabled.</p>
<p>Apache module <code>mod_rewrite</code> <strong>must</strong> be enabled to use the REST API. URL rewriting rules for the Slim microframework are stated in the root <code>.htaccess</code> file.</p>
<h2 id="lighthttpd">LightHttpd</h2>
<h2 id="nginx">Nginx</h2>
<h3 id="foreword">Foreword</h3>
<p>Nginx does not natively interpret PHP scripts; to this effect, we will run a <a href="https://en.wikipedia.org/wiki/FastCGI">FastCGI</a> service, to which Nginx's FastCGI module will proxy all requests to PHP resources.</p>
<p>Required packages:
- <a href="http://nginx.org">nginx</a>
- <a href="http://php-fpm.org">php-fpm</a> - PHP FastCGI Process Manager</p>
<p>Official documentation:
- <a href="http://nginx.org/en/docs/beginners_guide.html">Beginner's guide</a>
- <a href="http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html">ngx_http_fastcgi_module</a>
- <a href="http://wiki.nginx.org/Pitfalls">Pitfalls</a></p>
<p>Community resources:
- <a href="https://wiki.mozilla.org/Security/Server_Side_TLS#Nginx">Server-side TLS (Nginx)</a> (Mozilla)
- <a href="http://kbeezie.com/nginx-configuration-examples/">PHP configuration examples</a> (Karl Blessing)</p>
<h3 id="common-setup">Common setup</h3>
<p>Once Nginx and PHP-FPM are installed, we need to ensure:
- Nginx and PHP-FPM are running using the <em>same user and group</em>
- both these user and group have
    - <code>read</code> permissions for Shaarli resources
    - <code>execute</code> permissions for Shaarli directories <em>AND</em> their parent directories</p>
<p>On a production server:
- <code>user:group</code> will likely be <code>http:http</code>, <code>www:www</code> or <code>www-data:www-data</code>
- files will be located under <code>/var/www</code>, <code>/var/http</code> or <code>/usr/share/nginx</code></p>
<p>On a development server:
- files may be located in a user's home directory
- in this case, make sure both Nginx and PHP-FPM are running as the local user/group!</p>
<p>For all following configuration examples, this user/group pair will be used:
- <code>user:group = john:users</code>,</p>
<p>which corresponds to the following service configuration:</p>
<pre><code class="ini">; /etc/php/php-fpm.conf
user = john
group = users

[...]
listen.owner = john
listen.group = users
</code></pre>

<pre><code class="nginx"># /etc/nginx/nginx.conf
user john users;

http {
    [...]
}
</code></pre>

<h3 id="optional-increase-the-maximum-file-upload-size">(Optional) Increase the maximum file upload size</h3>
<p>Some bookmark dumps generated by web browsers can be <em>huge</em> due to the presence of Base64-encoded images and favicons, as well as extra verbosity when nesting links in (sub-)folders.</p>
<p>To increase upload size, you will need to modify both nginx and PHP configuration:</p>
<pre><code class="nginx"># /etc/nginx/nginx.conf

http {
    [...]

    client_max_body_size 10m;

    [...]
}
</code></pre>

<pre><code class="ini"># /etc/php5/fpm/php.ini

[...]
post_max_size = 10M
[...]
upload_max_filesize = 10M
</code></pre>

<h3 id="minimal_1">Minimal</h3>
<p><em>WARNING: Use for development only!</em> </p>
<pre><code class="nginx">user john users;
worker_processes  1;
events {
    worker_connections  1024;
}

http {
    include            mime.types;
    default_type       application/octet-stream;
    keepalive_timeout  20;

    index index.html index.php;

    server {
        listen       80;
        server_name  localhost;
        root         /home/john/web;

        access_log  /var/log/nginx/access.log;
        error_log   /var/log/nginx/error.log;

        location /shaarli/ {
            try_files $uri /shaarli/index.php$is_args$args;
            access_log  /var/log/nginx/shaarli.access.log;
            error_log   /var/log/nginx/shaarli.error.log;
        }

        location ~ (index)\.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
            fastcgi_index  index.php;
            include        fastcgi.conf;
        }
    }
}
</code></pre>

<h3 id="modular">Modular</h3>
<p>The previous setup is sufficient for development purposes, but has several major caveats:
- every content that does not match the PHP rule will be sent to client browsers:
    - dotfiles - in our case, <code>.htaccess</code>
    - temporary files, e.g. Vim or Emacs files: <code>index.php~</code>
- asset / static resource caching is not optimized
- if serving several PHP sites, there will be a lot of duplication: <code>location /shaarli/</code>, <code>location /mysite/</code>, etc.</p>
<p>To solve this, we will split Nginx configuration in several parts, that will be included when needed:</p>
<pre><code class="nginx"># /etc/nginx/deny.conf
location ~ /\. {
    # deny access to dotfiles
    access_log off;
    log_not_found off;
    deny all;
}

location ~ ~$ {
    # deny access to temp editor files, e.g. &quot;script.php~&quot;
    access_log off;
    log_not_found off;
    deny all;
}
</code></pre>

<pre><code class="nginx"># /etc/nginx/php.conf
location ~ (index)\.php$ {
    # Slim - split URL path into (script_filename, path_info)
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;

    # filter and proxy PHP requests to PHP-FPM
    fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
    fastcgi_index  index.php;
    include        fastcgi.conf;
}

location ~ \.php$ {
    # deny access to all other PHP scripts
    deny all;
}
</code></pre>

<pre><code class="nginx"># /etc/nginx/static_assets.conf
location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
    expires    max;
    add_header Pragma public;
    add_header Cache-Control &quot;public, must-revalidate, proxy-revalidate&quot;;
}
</code></pre>

<pre><code class="nginx"># /etc/nginx/nginx.conf
[...]

http {
    [...]

    root        /home/john/web;
    access_log  /var/log/nginx/access.log;
    error_log   /var/log/nginx/error.log;

    server {
        # virtual host for a first domain
        listen       80;
        server_name  my.first.domain.org;

        location /shaarli/ {
            # Slim - rewrite URLs
            try_files $uri /shaarli/index.php$is_args$args;

            access_log  /var/log/nginx/shaarli.access.log;
            error_log   /var/log/nginx/shaarli.error.log;
        }

        location = /shaarli/favicon.ico {
            # serve the Shaarli favicon from its custom location
            alias /var/www/shaarli/images/favicon.ico;
        }

        include deny.conf;
        include static_assets.conf;
        include php.conf;
    }

    server {
        # virtual host for a second domain
        listen       80;
        server_name  second.domain.com;

        location /minigal/ {
            access_log  /var/log/nginx/minigal.access.log;
            error_log   /var/log/nginx/minigal.error.log;
        }

        include deny.conf;
        include static_assets.conf;
        include php.conf;
    }
}
</code></pre>

<h3 id="redirect-http-to-https">Redirect HTTP to HTTPS</h3>
<p>Assuming you have generated a (self-signed) key and certificate, and they are located under <code>/home/john/ssl/localhost.{key,crt}</code>, it is pretty straightforward to set an HTTP (:80) to HTTPS (:443) redirection to force SSL/TLS usage.</p>
<pre><code class="nginx"># /etc/nginx/nginx.conf
[...]

http {
    [...]

    index index.html index.php;

    root        /home/john/web;
    access_log  /var/log/nginx/access.log;
    error_log   /var/log/nginx/error.log;

    server {
        listen       80;
        server_name  localhost;

        return 301 https://localhost$request_uri;
    }

    server {
        listen       443 ssl;
        server_name  localhost;

        ssl_certificate      /home/john/ssl/localhost.crt;
        ssl_certificate_key  /home/john/ssl/localhost.key;

        location /shaarli/ {
            # Slim - rewrite URLs
            try_files $uri /index.php$is_args$args;

            access_log  /var/log/nginx/shaarli.access.log;
            error_log   /var/log/nginx/shaarli.error.log;
        }

        location = /shaarli/favicon.ico {
            # serve the Shaarli favicon from its custom location
            alias /var/www/shaarli/images/favicon.ico;
        }

        include deny.conf;
        include static_assets.conf;
        include php.conf;
    }
}
</code></pre>
              
            </div>
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="../Server-security/" class="btn btn-neutral float-right" title="Server security">Next <span class="icon icon-circle-arrow-right"></span></a>
      
      
        <a href="../Server-requirements/" class="btn btn-neutral" title="Server requirements"><span class="icon icon-circle-arrow-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <!-- Copyright etc -->
    
  </div>

  Built with <a href="http://www.mkdocs.org">MkDocs</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
	  
        </div>
      </div>

    </section>
    
  </div>

  <div class="rst-versions" role="note" style="cursor: pointer">
    <span class="rst-current-version" data-toggle="rst-current-version">
      
          <a href="https://github.com/shaarli/Shaarli" class="fa fa-github" style="float: left; color: #fcfcfc"> GitHub</a>
      
      
        <span><a href="../Server-requirements/" style="color: #fcfcfc;">&laquo; Previous</a></span>
      
      
        <span style="margin-left: 15px"><a href="../Server-security/" style="color: #fcfcfc">Next &raquo;</a></span>
      
    </span>
</div>
    <script src="../js/theme.js"></script>

</body>
</html>