Parcourir la source

Convert Owncloud to nginx

Bob Mottram il y a 10 ans
Parent
révision
2c44fa56f6
1 fichiers modifiés avec 191 ajouts et 79 suppressions
  1. 191
    79
      beaglebone.txt

+ 191
- 79
beaglebone.txt Voir le fichier

@@ -2508,9 +2508,10 @@ The configuration for the site should look something like the following.  Replac
2508 2508
 #+BEGIN_SRC: bash
2509 2509
 server {
2510 2510
     listen 80;
2511
-    root /var/www/mydomainname.com/htdocs;
2512
-    index index.html index.htm;
2513 2511
     server_name mydomainname.com;
2512
+    root /var/www/mydomainname.com/htdocs;
2513
+    error_log /var/www/mydomainname.com/error.log;
2514
+    index index.html index.htm index.php;
2514 2515
 
2515 2516
     # Uncomment this if you need to redirect HTTP to HTTPS
2516 2517
     #rewrite ^ https://$server_name$request_uri? permanent;
@@ -2518,13 +2519,24 @@ server {
2518 2519
     location / {
2519 2520
         try_files $uri $uri/ /index.html;
2520 2521
     }
2522
+
2523
+    location ~ \.php$ {
2524
+        fastcgi_split_path_info ^(.+\.php)(/.+)$;
2525
+        fastcgi_pass unix:/var/run/php5-fpm.sock;
2526
+        fastcgi_index index.php;
2527
+        include fastcgi_params;
2528
+    }
2521 2529
 }
2522 2530
 
2523 2531
 server {
2524
-    listen 443;
2532
+    listen 443 ssl;
2525 2533
     root /var/www/mydomainname.com/htdocs;
2526
-    index index.html index.htm;
2527 2534
     server_name mydomainname.com;
2535
+    error_log /var/www/mydomainname.com/error_ssl.log;
2536
+    index index.html index.htm index.php;
2537
+    charset utf-8;
2538
+    client_max_body_size 20m;
2539
+    client_body_buffer_size 128k;
2528 2540
 
2529 2541
     ssl on;
2530 2542
     ssl_certificate /etc/ssl/certs/mydomainname.com.crt;
@@ -2538,8 +2550,61 @@ server {
2538 2550
     # use this only if all subdomains support HTTPS!
2539 2551
     # add_header Strict-Transport-Security "max-age=15768000; includeSubDomains";
2540 2552
 
2553
+    # rewrite to front controller as default rule
2541 2554
     location / {
2542
-        try_files $uri $uri/ /index.html;
2555
+        rewrite ^/(.*) /index.php?q=$uri&$args last;
2556
+    }
2557
+
2558
+    # make sure webfinger and other well known services aren't blocked
2559
+    # by denying dot files and rewrite request to the front controller
2560
+    location ^~ /.well-known/ {
2561
+        allow all;
2562
+        rewrite ^/(.*) /index.php?q=$uri&$args last;
2563
+    }
2564
+
2565
+    # statically serve these file types when possible
2566
+    # otherwise fall back to front controller
2567
+    # allow browser to cache them
2568
+    # added .htm for advanced source code editor library
2569
+    location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {
2570
+        expires 30d;
2571
+        try_files $uri /index.php?q=$uri&$args;
2572
+    }
2573
+
2574
+    # block these file types
2575
+    location ~* \.(tpl|md|tgz|log|out)$ {
2576
+        deny all;
2577
+    }
2578
+
2579
+    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
2580
+    # or a unix socket
2581
+    location ~* \.php$ {
2582
+        # Zero-day exploit defense.
2583
+        # http://forum.nginx.org/read.php?2,88845,page=3
2584
+        # Won't work properly (404 error) if the file is not stored on this
2585
+        # server, which is entirely possible with php-fpm/php-fcgi.
2586
+        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on
2587
+        # another machine. And then cross your fingers that you won't get hacked.
2588
+        try_files $uri =404;
2589
+        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
2590
+        fastcgi_split_path_info ^(.+\.php)(/.+)$;
2591
+        # With php5-cgi alone:
2592
+        # fastcgi_pass 127.0.0.1:9000;
2593
+        # With php5-fpm:
2594
+        fastcgi_pass unix:/var/run/php5-fpm.sock;
2595
+        include fastcgi_params;
2596
+        fastcgi_index index.php;
2597
+        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
2598
+    }
2599
+
2600
+    # deny access to all dot files
2601
+    location ~ /\. {
2602
+        deny all;
2603
+    }
2604
+
2605
+    #deny access to store
2606
+    location ~ /store {
2607
+        deny all;
2543 2608
     }
2544 2609
 }
2545 2610
 #+END_SRC
@@ -2606,8 +2671,19 @@ Set the following:
2606 2671
 memory_limit = 32M
2607 2672
 #+END_SRC
2608 2673
 
2674
+Also set:
2675
+
2676
+#+BEGIN_SRC: bash
2677
+cgi.fix_pathinfo=0
2678
+#+END_SRC
2679
+
2609 2680
 Save and exit.  Also edit */etc/php5/cli/php.ini* and set /memory_limit/ to the same value.  This should prevent any rogue scripts from crashing the system.
2610 2681
 
2682
+#+BEGIN_SRC: bash
2683
+service php5-fpm restart
2684
+service nginx restart
2685
+#+END_SRC
2686
+
2611 2687
 ** Accessing your Email
2612 2688
 
2613 2689
 #+BEGIN_VERSE
@@ -2850,32 +2926,30 @@ rm /var/www/$HOSTNAME/htdocs/mail/.htaccess
2850 2926
 Edit your web site configuration.
2851 2927
 
2852 2928
 #+BEGIN_SRC: bash
2853
-editor /etc/apache2/sites-available/$HOSTNAME
2929
+editor /etc/nginx/sites-available/$HOSTNAME
2854 2930
 #+END_SRC
2855 2931
 
2856 2932
 Within the 80 VirtualHost section add the following:
2857 2933
 
2858 2934
 #+BEGIN_SRC: bash
2859
-  <Directory /var/www/mydomainname.com/htdocs/mail>
2860
-    deny from all
2861
-  </Directory>
2935
+    location /mail/ {
2936
+        deny all;
2937
+    }
2862 2938
 #+END_SRC
2863 2939
 
2864 2940
 Within the 443 VirtualHost section add the following:
2865 2941
 
2866 2942
 #+BEGIN_SRC: bash
2867
-  <Directory /var/www/mydomainname.com/htdocs/mail>
2868
-    Options Indexes FollowSymLinks MultiViews
2869
-    AllowOverride All
2870
-    Order allow,deny
2871
-    allow from all
2872
-  </Directory>
2943
+    location /mail/ {
2944
+        autoindex on;
2945
+        allow all;
2946
+    }
2873 2947
 #+END_SRC
2874 2948
 
2875 2949
 Save and exit, then restart Apache.
2876 2950
 
2877 2951
 #+BEGIN_SRC: bash
2878
-service apache2 restart
2952
+service nginx restart
2879 2953
 #+END_SRC
2880 2954
 
2881 2955
 Now with a browser visit https://mydomainname.com/mail/installer. Scroll down and click "next".  Give your webmail site a product name.
@@ -4282,7 +4356,7 @@ MYSQL_PASSWORD=<mysql root password>
4282 4356
 umask 0077
4283 4357
 
4284 4358
 # stop the web server to avoid any changes to the databases during backup
4285
-service apache2 stop
4359
+service nginx stop
4286 4360
 
4287 4361
 # Save to a temporary file first so that it can be checked for non-zero size
4288 4362
 TEMPFILE=/tmp/friendicared.sql
@@ -4366,7 +4440,7 @@ DAILYFILE=/var/backups/redmatrix_daily.sql
4366 4440
 
4367 4441
 
4368 4442
 # restart the web server
4369
-service apache2 start
4443
+service nginx start
4370 4444
 
4371 4445
 exit 0
4372 4446
 #+END_SRC
@@ -5408,61 +5482,110 @@ Owncloud will allow you to upload and download files, share photos, collaborativ
5408 5482
 Install some dependencies:
5409 5483
 
5410 5484
 #+BEGIN_SRC: bash
5411
-apt-get install apache2 php5 php5-gd php-xml-parser php5-intl
5485
+apt-get install php5 php5-gd php-xml-parser php5-intl
5412 5486
 apt-get install php5-sqlite php5-mysql smbclient curl libcurl3 php5-curl
5413 5487
 #+END_SRC
5414 5488
 
5415
-It's very important that /mod_php5/ and not /mod_php5filter/ be installed.  If you have /mod_php5filter/ installed then Owncloud will always fail to install.
5489
+You will need to create a new subdomain, so see [[Setting up a web site]] for details of how to do that.
5416 5490
 
5417 5491
 #+BEGIN_SRC: bash
5418
-a2dismod php5filter
5419
-apt-get install libapache2-mod-php5
5492
+export HOSTNAME=myowncloudcomainname.com
5493
+editor /etc/nginx/sites-available/$HOSTNAME
5420 5494
 #+END_SRC
5421 5495
 
5422
-Ensure that the size of files which may be uploaded or downloaded is large enough.
5496
+Delete all existing contents, then add the following:
5423 5497
 
5424 5498
 #+BEGIN_SRC: bash
5425
-editor /etc/php5/apache2/php.ini
5426
-#+END_SRC
5499
+server {
5500
+    listen 80;
5501
+    server_name myownclouddomainname.com;
5502
+    rewrite ^ https://$server_name$request_uri? permanent;
5503
+}
5427 5504
 
5428
-Set the following:
5505
+server {
5506
+    listen 443 ssl;
5507
+    root /var/www/myownclouddomainname.com/htdocs;
5508
+    server_name myownclouddomainname.com;
5429 5509
 
5430
-#+BEGIN_SRC: bash
5431
-upload_max_filesize = 512M
5432
-post_max_size = 512M
5433
-#+END_SRC
5510
+    ssl on;
5511
+    ssl_certificate /etc/ssl/certs/myownclouddomainname.com.crt;
5512
+    ssl_certificate_key /etc/ssl/private/myownclouddomainname.com.key;
5434 5513
 
5435
-Save and exit, then edit your Apache configuration.
5514
+    ssl_session_timeout 5m;
5515
+    ssl_prefer_server_ciphers on;
5516
+    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # not possible to do exclusive
5517
+    ssl_ciphers 'EDH+CAMELLIA:EDH+aRSA:EECDH+aRSA+AESGCM:EECDH+aRSA+SHA384:EECDH+aRSA+SHA256:EECDH:+CAMELLIA256:+AES256:+CAMELLIA128:+AES128:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!DSS:!RC4:!SEED:!ECDSA:CAMELLIA256-SHA:AES256-SHA:CAMELLIA128-SHA:AES128-SHA';
5518
+    add_header Strict-Transport-Security max-age=15768000; # six months
5519
+    # use this only if all subdomains support HTTPS!
5520
+    # add_header Strict-Transport-Security "max-age=15768000; includeSubDomains";
5436 5521
 
5437
-#+BEGIN_SRC: bash
5438
-export HOSTNAME=mydomainname.com
5439
-editor /etc/apache2/sites-available/$HOSTNAME
5440
-#+END_SRC
5522
+    # make sure webfinger and other well known services aren't blocked
5523
+    # by denying dot files and rewrite request to the front controller
5524
+    location ^~ /.well-known/ {
5525
+        allow all;
5526
+        rewrite ^/(.*) /index.php?q=$uri&$args last;
5527
+    }
5441 5528
 
5442
-And add the following, to the 443 VirtualHost section.  Really we only will want to be using Owncloud with HTTPS to ensure some level of security and avoidance of dragnet surveillance.
5529
+    client_max_body_size 10G; # set max upload size
5530
+    client_body_buffer_size 128k;
5531
+    fastcgi_buffers 64 4K;
5443 5532
 
5444
-#+BEGIN_SRC: bash
5445
-  <Directory /var/www/mydomainname.com/htdocs/owncloud>
5446
-    Options Indexes FollowSymLinks MultiViews
5447
-    AllowOverride All
5448
-    Order allow,deny
5449
-    allow from all
5450
-    LimitRequestBody 536870912
5451
-  </Directory>
5452
-#+END_SRC
5533
+    rewrite ^/caldav(.*)$ /remote.php/caldav$1 redirect;
5534
+    rewrite ^/carddav(.*)$ /remote.php/carddav$1 redirect;
5535
+    rewrite ^/webdav(.*)$ /remote.php/webdav$1 redirect;
5453 5536
 
5454
-To ensure that nobody logs in insecurely add the following to the 80 VirtualHost section.
5537
+    index index.php;
5538
+    error_page 403 /core/templates/403.php;
5539
+    error_page 404 /core/templates/404.php;
5455 5540
 
5456
-#+BEGIN_SRC: bash
5457
-  <Directory /var/www/mydomainname.com/htdocs/owncloud>
5458
-    deny from all
5459
-  </Directory>
5541
+    location = /robots.txt {
5542
+        allow all;
5543
+        log_not_found off;
5544
+        access_log off;
5545
+    }
5546
+
5547
+    location ~ ^/(data|config|\.ht|db_structure\.xml|README) {
5548
+        deny all;
5549
+    }
5550
+
5551
+    location / {
5552
+        # The following 2 rules are only needed with webfinger
5553
+        rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
5554
+        rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;
5555
+
5556
+        rewrite ^/.well-known/carddav /remote.php/carddav/ redirect;
5557
+        rewrite ^/.well-known/caldav /remote.php/caldav/ redirect;
5558
+
5559
+        rewrite ^(/core/doc/[^\/]+/)$ $1/index.html;
5560
+
5561
+        try_files $uri $uri/ index.php;
5562
+    }
5563
+
5564
+    location ~ ^(.+?\.php)(/.*)?$ {
5565
+        try_files $1 =404;
5566
+        fastcgi_split_path_info ^(.+\.php)(/.+)$;
5567
+        fastcgi_pass unix:/var/run/php5-fpm.sock;
5568
+        fastcgi_index index.php;
5569
+        include fastcgi_params;
5570
+        fastcgi_param SCRIPT_FILENAME $document_root$1;
5571
+        fastcgi_param PATH_INFO $2;
5572
+        fastcgi_param HTTPS on;
5573
+    }
5574
+
5575
+    # Optional: set long EXPIRES header on static assets
5576
+    location ~* ^.+\.(jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {
5577
+        expires 30d;
5578
+        # Optional: Don't log access to assets
5579
+        access_log off;
5580
+    }
5581
+}
5460 5582
 #+END_SRC
5461 5583
 
5462
-Save and exit, then restart apache.
5584
+Save and exit. Then change the domain name.
5463 5585
 
5464 5586
 #+BEGIN_SRC: bash
5465
-service apache2 restart
5587
+sed "s/myownclouddomainname.com/$HOSTNAME/g" /etc/nginx/sites-available/$HOSTNAME > /tmp/website
5588
+cp -f /tmp/website /etc/nginx/sites-available/$HOSTNAME
5466 5589
 #+END_SRC
5467 5590
 
5468 5591
 Download owncloud.
@@ -5483,40 +5606,23 @@ sha256sum owncloud.tar.bz2
5483 5606
 Extract the archive.  This may take a couple of minutes, so don't be alarmed that the system has crashed.
5484 5607
 
5485 5608
 #+BEGIN_SRC: bash
5486
-export HOSTNAME=mydomainname.com
5487 5609
 tar -xjf owncloud.tar.bz2
5488 5610
 #+END_SRC
5489 5611
 
5490 5612
 The extraction will take a few minutes. Move the extracted files to your site and set file permissions.
5491 5613
 
5492 5614
 #+BEGIN_SRC: bash
5493
-cp -r owncloud /var/www/$HOSTNAME/htdocs
5615
+cp -r owncloud/* /var/www/$HOSTNAME/htdocs
5494 5616
 #+END_SRC
5495 5617
 
5496 5618
 The copying also takes a few minutes. Then change the file permissions.
5497 5619
 
5498 5620
 #+BEGIN_SRC: bash
5499
-chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/owncloud/apps
5500
-chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/owncloud/config
5501
-chown www-data:www-data /var/www/$HOSTNAME/htdocs/owncloud
5502
-#+END_SRC
5503
-
5504
-Edit the htaccess file for Owncloud.
5505
-
5506
-#+BEGIN_SRC: bash
5507
-editor /var/www/$HOSTNAME/htdocs/owncloud/.htaccess
5508
-#+END_SRC
5509
-
5510
-Set the following.
5511
-
5512
-#+BEGIN_SRC: bash
5513
-php_value upload_max_filesize 512M
5514
-php_value post_max_size 512M
5515
-php_value memory_limit 32M
5621
+chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/apps
5622
+chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/config
5623
+chown www-data:www-data /var/www/$HOSTNAME/htdocs
5516 5624
 #+END_SRC
5517 5625
 
5518
-Save and exit.
5519
-
5520 5626
 With a web browser visit your domain (mydomainname.com/owncloud) and enter an administrator username and password.
5521 5627
 
5522 5628
 For extra security you may also wish to create an ordinary owncloud user with limited privileges. To do that click on the *settings* dropdown menu (top right) then *users* then enter a *Login Name* and *password* and click on *create*. Under *quota* select a size which is suitable for the remaining space on your microSD card, then select the settings menu from the top right and select *log out*. You can now log back in as your new user.
@@ -8147,22 +8253,28 @@ cp /etc/ssl/private/$HOSTNAME.new.key /etc/ssl/private/$HOSTNAME.key
8147 8253
 shred -zu /etc/ssl/private/$HOSTNAME.new.key
8148 8254
 #+END_SRC
8149 8255
 
8150
-Edit your Apache configuration file.
8256
+Create a bundled certificate which joins the certificate and chain file together.
8151 8257
 
8152 8258
 #+BEGIN_SRC: bash
8153
-editor /etc/apache2/sites-available/$HOSTNAME
8259
+cat /etc/ssl/certs/$HOSTNAME.crt /etc/ssl/chains/startssl-sub.class1.server.ca.pem > /etc/ssl/certs/$HOSTNAME.bundle.crt
8154 8260
 #+END_SRC
8155 8261
 
8156
-Add the following to the section which starts with *<VirtualHost *:443>*
8262
+Edit your configuration file.
8157 8263
 
8158 8264
 #+BEGIN_SRC: bash
8159
-	SSLCertificateChainFile /etc/ssl/chains/startssl-sub.class1.server.ca.pem
8265
+editor /etc/nginx/sites-available/$HOSTNAME
8160 8266
 #+END_SRC
8161 8267
 
8162
-Save and exit, then restart apache.
8268
+Add the following to the section which starts with *listen 443*
8163 8269
 
8164 8270
 #+BEGIN_SRC: bash
8165
-service apache2 restart
8271
+    ssl_certificate /etc/ssl/certs/mydomainname.com_bundle.crt;
8272
+#+END_SRC
8273
+
8274
+Save and exit, then restart the web server.
8275
+
8276
+#+BEGIN_SRC: bash
8277
+service nginx restart
8166 8278
 #+END_SRC
8167 8279
 
8168 8280
 Now visit your web site at https://mydomainname.com and you should notice that there is no certificate warning displayed.  You will now be able to install systems which don't allow the use of self-signed certificates, such as [[https://redmatrix.me/&JS=1][Red Matrix]].