iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 6
0
Mobile Development

小菜逼學習IOS系列 第 6

學習NextCloud IOS APP 倒數第25篇 -NextCloud 伺服器架設(下)

如果還沒完成上部分的話請點擊這裡喔,如果上部分也完成者,那就開幹囉
NextCloud 還需要一些PHP套件,所以我們要先安裝

sudo apt-get install php-xml php-zip php-mbstring php-curl php-gd

安裝後再去NextCloud官網下載安裝包點我,點進去後點擊Download for server,就會看到Download Nextcloud,把它載下來。

再將下載完的安裝包解壓縮,並上傳到伺服器的資料夾中(如果是LEMP環境預設是在/var/www/html中)
這邊示範的是 /var/www/html/nextcloud
接著是把NextCloud 的擁有者給 nginx:

sudo chown -R www-data nextcloud

然後nginx需要設定rewrite轉給index.php 輸入指令修改設定:

sudo nano /etc/nginx/sites-available/default

將原本的設定再添加一點 (如果走https協定請把 fastcgi_param HTTPS on; 的註解去除)

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/html;

    index index.php index.html index.htm index.nginx-debian.html;

    server_name _;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }    
     以下都是要添加的

    location ^~ /nextcloud {
        # set max upload size
        client_max_body_size 512M;
        fastcgi_buffers 64 4K;

        # Enable gzip but do not remove ETag headers
        gzip on;
        gzip_vary on;
        gzip_comp_level 4;
        gzip_min_length 256;
        gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
        gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;

        # Uncomment if your server is build with the ngx_pagespeed module
        # This module is currently not supported.
        #pagespeed off;

        location /nextcloud {
            rewrite ^ /nextcloud/index.php$request_uri;
        }

        location ~ ^/nextcloud/(?:build|tests|config|lib|3rdparty|templates|data)/ {
            deny all;
        }

        location ~ ^/nextcloud/(?:\.|autotest|occ|issue|indie|db_|console) {
            deny all;
        }

        location ~ ^/nextcloud/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+)\.php(?:$|/) {
            fastcgi_split_path_info ^(.+?\.php)(/.*)$;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_path_info;
            # fastcgi_param HTTPS on;
            # Avoid sending the security headers twice
            fastcgi_param modHeadersAvailable true;
            fastcgi_param front_controller_active true;
            fastcgi_pass unix:/run/php/php7.2-fpm.sock;
            fastcgi_intercept_errors on;
            fastcgi_request_buffering off;
        }

        location ~ ^/nextcloud/(?:updater|ocs-provider)(?:$|/) {
            try_files $uri/ =404;
            index index.php;
        }

        # Adding the cache control header for js and css files
        # Make sure it is BELOW the PHP block
        location ~ \.(?:css|js|woff|svg|gif)$ {
            try_files $uri /nextcloud/index.php$request_uri;
            add_header Cache-Control "public, max-age=15778463";
            # Add headers to serve security related headers  (It is intended
            # to have those duplicated to the ones above)
            # Before enabling Strict-Transport-Security headers please read
            # into this topic first.
            # add_header Strict-Transport-Security "max-age=15768000;
            # includeSubDomains; preload;";
            add_header X-Content-Type-Options nosniff;
            add_header X-XSS-Protection "1; mode=block";
            add_header X-Robots-Tag none;
            add_header X-Download-Options noopen;
            add_header X-Permitted-Cross-Domain-Policies none;
            # Optional: Don't log access to assets
            access_log off;
        }

        location ~ \.(?:png|html|ttf|ico|jpg|jpeg)$ {
            try_files $uri /nextcloud/index.php$request_uri;
            # Optional: Don't log access to other assets
            access_log off;
        }
    }
}

修改完成後輸入以下指令讓nginx重新讀取設定檔

sudo systemctl reload nginx

此時開啟網頁http://your_host/nextcloud 不是打your_host
然後設定自己想要的管理員帳號密碼、雲端硬碟資料儲存位置、以及資料庫帳號密碼,輸入完成後按 [Finish setup]再給它點時間
接著就能進入雲端硬碟頁面
就完成囉
如果要新增使用者,點擊右上角,再點擊Users就能添加了喔。


上一篇
學習NextCloud IOS APP 倒數第26篇 -第三方套件(下)
下一篇
tableview基本教學與套件FastScroll操作(上) - 倒數第24篇
系列文
小菜逼學習IOS30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言