Instal Nextcloud dengan Nginx dan Sertifikat SSL/TLS di CentOS 8

Selamat datang di panduan kami tentang solusi sinkronisasi dan berbagi file perusahaan lainnya. Kita akan belajar cara menginstal Nextcloud dengan Nginx dan Sertifikat SSL/TLS di CentOS 8.

Ingin mencoba ownCloud? Lihat panduan kami tentang menyiapkan server ownCloud di CentOS 8 dengan mengikuti tautan di bawah ini;

Instal Server ownCloud di CentOS 8

Instal Nextcloud dengan Nginx dan Sertifikat SSL/TLS di CentOS 8

Untuk menginstal Nextcloud dengan Nginx dan Sertifikat SSL/TLS di CentOS 8, ini adalah langkah-langkah yang digunakan di lingkungan kami. Jangan ragu untuk memodifikasi langkah-langkah agar sesuai dengan lingkungan Anda.

Jalankan Pembaruan Sistem

Pastikan paket sistem Anda mutakhir.

dnf update

Instal LEMP Stack

Untuk menjalankan Nextcloud dengan Nginx, Anda harus terlebih dahulu menyiapkan stack LEMP. Kami telah menyediakan panduan tentang cara mengatur stack LEMP di CentOS 8 di panduan kami sebelumnya. Ikuti tautan di bawah ini;

Instal LEMP Stack di CentOS 8

Instal Modul PHP Lainnya yang Diperlukan

Untuk menginstal modul PHP lain yang diperlukan dan paket lainnya, jalankan perintah di bawah ini;

dnf install php-gd php-json php-curl php-mbstring php-intl php-xml php-zip php-pear php-soap

Instal paket lain yang diperlukan;

dnf install zip wget tar policycoreutils-python-utils

Konfigurasi PHP

Edit /etc/php.inidan atur nilainya cgi.fix_pathinfomenjadi0.

vim /etc/php.ini
... ;cgi.fix_pathinfo=1 cgi.fix_pathinfo=0...

Edit /etc/php-fpm.d/www.confdan buat perubahan berikut;

vim /etc/php-fpm.d/www.conf
... user = nginx group = nginx... # Uncomment these lines by removing the ; at the beginning of the lines. env[HOSTNAME] = $HOSTNAME env[PATH] = /usr/local/bin:/usr/bin:/bin env[TMP] = /tmp env[TMPDIR] = /tmp env[TEMP] = /tmp...

Buat Database Nextcloud dan Pengguna Database

Sebelum Anda dapat membuat database MariaDB/MySQL untuk Nextcloud, pastikan bahwa InnoDB adalah engine penyimpanan default;

mysql -u root -p
show engines;
+--------------------+---------+----------------------------------------------------------------------------------+--------------+------+------------+ | Engine | Support | Comment | Transactions | XA | Savepoints | +--------------------+---------+----------------------------------------------------------------------------------+--------------+------+------------+...... | InnoDB | DEFAULT | Supports transactions, row-level locking, foreign keys and encryption for tables | YES | YES | YES |...

Pastikan bahwa dukungan diatur ke DEFAULT.

Selanjutnya, buat database Nextcloud (names of the database and database user used here are not standard, use whatever names you like).

create database ncdb;

Buat user database Nextcloud dengan hak penuh yang diberikan pada database Nextcloud.

grant all privileges on ncdb.* to [email protected] identified by '[email protected]';

Reload tabel hak istimewa dan keluar dari DB.

flush privileges; quit

Download dan Instal Nextcloud

Dalam panduan ini, kita akan menginstal Nextcloud dari sumbernya. Karena itu, download versi rilis stabil terbaru dari Nextcloud, v17.0.2, pada saat tulisan ini dibuat dari halaman rilis.

wget https://download.nextcloud.com/server/releases/latest.zip

Ekstrak Nextcloud ke Direktori Root Web

Karena kami menggunakan Nginx sebagai server Web kami, kami akan menempatkan file dan konfigurasi Nextcloud di bawah, /usr/share/nginx/html/nextcloud. Jalurnya mungkin berbeda untuk kasus Anda.

unzip latest.zip -d /usr/share/nginx/html/

Hasilkan Sertifikat SSL/TLS

Nah, untuk menyiapkan Nextcloud dengan sertifikat SSL/TLS, Anda harus membuat sertifikat terlebih dahulu. Panduan ini menggunakan sertifikat yang ditandatangani sendiri untuk tujuan demonstrasi. Jika Anda menjalankan Nextcloud di lingkungan produksi, pertimbangkan untuk menggunakan sertifikat tepercaya publik dari CA pilihan Anda.

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/pki/tls/nc-selfsigned.key -out /etc/pki/tls/nc-selfsigned.crt

Mengonfigurasi Nginx untuk Nextcloud

Nextcloud menyediakan contoh kode konfigurasi Nginx untuk Nextcloud. Anda cukup mengambil konfigurasi dan menyesuaikannya agar sesuai dengan pengaturan lingkungan Anda.

vim /etc/nginx/conf.d/nextcloud.conf

Be sure to replace the server name, the web root directory, the path to the SSL/TLS certificates accordingly.

upstream php-handler { server unix:/run/php-fpm/www.sock; } server { listen 80; server_name nextcloud.kifarunix-demo.com; # enforce https return 301 https://$server_name:443$request_uri; } server { listen 443 ssl http2; server_name nextcloud.kifarunix-demo.com; ssl_certificate /etc/pki/tls/nc-selfsigned.crt; ssl_certificate_key /etc/pki/tls/nc-selfsigned.key; add_header Referrer-Policy "no-referrer" always; add_header X-Content-Type-Options "nosniff" always; add_header X-Download-Options "noopen" always; add_header X-Frame-Options "SAMEORIGIN" always; add_header X-Permitted-Cross-Domain-Policies "none" always; add_header X-Robots-Tag "none" always; add_header X-XSS-Protection "1; mode=block" always; fastcgi_hide_header X-Powered-By; # Path to the root of your installation root /usr/share/nginx/html/nextcloud; access_log /var/log/nginx/nc_access_log; error_log /var/log/nginx/nc_error_log; location = /robots.txt { allow all; log_not_found off; access_log off; } location = /.well-known/carddav { return 301 $scheme://$host:$server_port/remote.php/dav; } location = /.well-known/caldav { return 301 $scheme://$host:$server_port/remote.php/dav; } # 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; location / { rewrite ^ /index.php; } location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ { deny all; } location ~ ^/(?:.|autotest|occ|issue|indie|db_|console) { deny all; } location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|oc[ms]-provider/.+).php(?:$|/) { fastcgi_split_path_info ^(.+?.php)(/.*|)$; set $path_info $fastcgi_path_info; try_files $fastcgi_script_name =404; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $path_info; fastcgi_param HTTPS on; fastcgi_param modHeadersAvailable true; fastcgi_param front_controller_active true; fastcgi_pass php-handler; fastcgi_intercept_errors on; fastcgi_request_buffering off; } location ~ ^/(?:updater|oc[ms]-provider)(?:$|/) { try_files $uri/ =404; index index.php; } location ~.(?:css|js|woff2?|svg|gif|map)$ { try_files $uri /index.php$request_uri; add_header Cache-Control "public, max-age=15778463"; add_header Referrer-Policy "no-referrer" always; add_header X-Content-Type-Options "nosniff" always; add_header X-Download-Options "noopen" always; add_header X-Frame-Options "SAMEORIGIN" always; add_header X-Permitted-Cross-Domain-Policies "none"
always; add_header X-Robots-Tag "none" always; add_header X-XSS-Protection "1; mode=block" always; access_log off; } location ~.(?:png|html|ttf|ico|jpg|jpeg|bcmap)$ { try_files $uri /index.php$request_uri; access_log off; } }

Simpan dan keluar dari file konfigurasi.

Buat direktori data Nextcloud;

mkdir /usr/share/nginx/html/nextcloud/data

Setel kepemilikan user dan grup dari direktori Nextcloud ke nginx.

chown -R nginx:nginx /usr/share/nginx/html/nextcloud

Tetapkan izin yang tepat untuk direktori dan file Nextcloud.

find /usr/share/nginx/html/nextcloud/ -type d -exec chmod 750 {} ;
find /usr/share/nginx/html/nextcloud/ -type f -exec chmod 640 {} ;

Setel kepemilikan direktori sesi PHP ke nginx.

chown nginx:nginx -R /var/lib/php/session/

Verifikasi Nginx untuk error sintaks.

nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful

Mulai ulang Nginx dan PHP-FPM.

systemctl restart nginx php-fpm

Izinkan lalu lintas HTTP/HTTPS Nginx di FirewallD

Jika firewallD sedang berjalan, jalankan perintah di bawah ini untuk membuka port 80 dan 443.

firewall-cmd --add-port={80,443}/tcp --permanent
firewall-cmd --reload

Konfigurasi SELinux

Selain itu, Nextcloud menyediakan konfigurasi SELinux yang setidaknya harus memperbaiki masalah izin dengan Nextcloud. Jalankan perintah di bawah ini dan pastikan untukreplace the Nextcloud installation paths demikian.

semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/nextcloud/data(/.*)?' semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/nextcloud/config(/.*)?' semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/nextcloud/apps(/.*)?' semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/nextcloud/.htaccess' semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/nextcloud/.user.ini' semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/nextcloud/3rdparty/aws/aws-sdk-php/src/data/logs(/.*)?' restorecon -Rv '/usr/share/nginx/html/nextcloud/'

Selesaikan Pengaturan Nextcloud di Browser

Anda sekarang dapat mengakses Nextcloud dari browser untuk menyelesaikan instalasi dan pengaturan. Perhatikan bahwa kami telah mengonfigurasi pengalihan HTTP ke HTTPS karenanya, jika Anda mengakses Nextcloud menggunakan URL, nextcloud.kifarunix-demo.com(ganti yang sesuai), Anda akan diarahkan ke HTTPS dan karena kami menggunakan sertifikat SSL/TLS yang ditandatangani sendiri, lewati peringatan;

Pada interface user Nextcloud, masukkan nama dan password untuk user admin Nextcloud.

Selanjutnya, Anda perlu menentukan database backend Anda dan detail koneksi. Dalam demo ini, kami menggunakan MariaDB dan klik padastorage and databasedrop down, atur direktori data Nextcloud, pilih MySQL/MariaDBsebagai database dan atur detail koneksi seperti yang dibuat di atas.

Klik Finish setup untuk menyelesaikan konfigurasi.

Setelah pengaturan selesai, Anda akan disambut oleh jendela login.

Masukkan kredensial admin yang dibuat selama penyiapan dan masuk ke Nextcloud.

Itu menandai akhir dari tutorial kami tentang cara menginstal Nextcloud dengan Nginx dan Sertifikat SSL/TLS di CentOS 8. Sekarang Anda dapat menjelajahi alat yang luar biasa ini lebih lanjut.

Referensi

Manual administrasi terbaru Nextcloud

Tutorial Terkait

Konfigurasikan Otentikasi OpenLDAP ownCloud

Instal Server ownCloud di Debian 10 Buster

Instal Client Desktop ownCloud di CentOS 8

Instal Client Desktop ownCloud di Debian 10 Buster