Seafile là một nền tảng chia sẻ và đồng bộ hóa tệp tự lưu trữ, mã nguồn mở. Nó cho phép người dùng lưu trữ và mã hóa dữ liệu trên máy chủ của họ mà không cần dựa vào nhà cung cấp đám mây của bên thứ ba. Seafile cho phép bạn chia sẻ tệp và thư mục bằng cách sử dụng đồng bộ hóa đa nền tảng và liên kết được bảo vệ bằng mật khẩu đến các tệp có ngày hết hạn. Seafile cũng tạo phiên bản cho các tệp cho phép người dùng khôi phục các tệp hoặc thư mục đã xóa và đã sửa đổi.
Trong hướng dẫn này, bạn sẽ học cách cài đặt Seafile trên máy chủ Ubuntu 22.04, MySQL và Nginx làm máy chủ proxy ngược.
[*]
Một số gói mà hệ thống của bạn cần.
Một số gói này có thể đã được cài đặt trên hệ thống của bạn.
Kiểm tra xem tường lửa có đang chạy không.
Bạn sẽ nhận được kết quả sau.
Cho phép cổng SSH để tường lửa không làm gián đoạn kết nối hiện tại khi bật nó.
Cho phép cả cổng HTTP và HTTPS.
Kích hoạt Tường lửa
Kiểm tra lại trạng thái của tường lửa.
Bạn sẽ thấy kết quả tương tự.
Chạy lệnh sau để cài đặt các công cụ Python, trình quản lý gói Pip, thư viện SQL và Memcached.
Chạy lệnh sau để cài đặt các phụ thuộc Python.
Kiểm tra phiên bản MySQL.
Bước này cần thiết cho MySQL phiên bản 8.0.28 trở lên. Nhập MySQL Shell.
Chạy lệnh sau để đặt mật khẩu cho người dùng root của bạn. Đảm bảo rằng nó có sự kết hợp giữa số, chữ hoa, chữ thường và ký tự đặc biệt.
Thoát khỏi shell.
Chạy cài đặt bảo mật MySQL script.
Đầu tiên, bạn sẽ được yêu cầu nhập mật khẩu gốc. Nhập mật khẩu. Tiếp theo, bạn sẽ được yêu cầu cài đặt Validate Password Component. Nó kiểm tra độ mạnh của mật khẩu được sử dụng trong MySQL. Nhấn Y để cài đặt. Tiếp theo, bạn sẽ được yêu cầu đặt mức chính sách xác thực mật khẩu. Chọn 2 vì đây là mức mạnh nhất.
Tiếp theo, nhập N để từ chối thay đổi mật khẩu gốc của bạn. Ngoài ra, hãy nhập Y để xóa người dùng ẩn danh, không cho phép đăng nhập root từ xa, xóa cơ sở dữ liệu thử nghiệm và tải lại bảng đặc quyền.
Tạo ba cơ sở dữ liệu sau.
Tạo tài khoản người dùng SQL để truy cập các cơ sở dữ liệu này. Seafile chỉ hoạt động với plugin xác thực
Cấp tất cả các quyền trên ba cơ sở dữ liệu cho người dùng.
Xóa quyền người dùng.
Thoát khỏi shell.
Tạo người dùng cho Seafile.
Thay đổi quyền sở hữu thư mục cho người dùng mới.
Truy cập trang tải xuống Seafile và lấy liên kết tải xuống phiên bản mới nhất của Seafile. Tại thời điểm viết hướng dẫn này, phiên bản mới nhất là 10.0.1.
Tải xuống kho lưu trữ máy chủ Seafile.
Giải nén kho lưu trữ.
Chuyển sang Seafile thư mục.
Chạy tập lệnh cài đặt Seafile.
Tập lệnh cài đặt sẽ bắt đầu. Nhấn phím ENTER để tiếp tục.
Tiếp theo, cấu hình máy chủ Seafile của bạn bằng cách cung cấp tên cho máy chủ, tên miền (seafile.example.com) và cổng. Bạn có thể để trống trường cổng để Seafile giữ nguyên cổng mặc định là 8082. Sau khi cấu hình xong, hãy nhấn phím ENTER để tiếp tục.
Tiếp theo, bạn sẽ được yêu cầu chọn cách khởi tạo cơ sở dữ liệu Seafile. Vì chúng ta đã tạo cơ sở dữ liệu, hãy chọn tùy chọn thứ 2.
Tiếp theo, bạn sẽ được yêu cầu nhập thông tin chi tiết về cơ sở dữ liệu cho Seafile. Để trống các trường host và port để Seafile chọn các giá trị mặc định. Nhập các giá trị khác như đã cấu hình ở Bước 4.
Tiếp theo, bạn sẽ được hiển thị các cấu hình Seafile của mình. Nhấn phím ENTER để tiếp tục cài đặt.
Bạn sẽ thấy màn hình sau nếu cài đặt thành công.
Chạy lệnh sau để bắt đầu Seaf-server.
Bạn sẽ nhận được kết quả đầu ra sau.
Chạy lệnh sau để khởi động Seahub.
Lần đầu tiên Seahub khởi động, bạn sẽ được nhắc nhập thông tin chi tiết về tài khoản quản trị viên.
Dừng Seafile và Seahub máy chủ.
Thêm tham số
Lưu tệp bằng cách nhấn Ctrl + X và nhập Y khi được nhắc.
Mở tệp
Sửa đổi giá trị của
Thêm dòng sau vào bên dưới nó.
Thêm mã sau vào cuối tệp.
Lưu tệp bằng cách nhấn Ctrl + X và nhập Y khi được nhắc.
Thoát khỏi người dùng Seafile shell.
Tạo và mở tệp
Dán mã sau vào đó.
Lưu tệp bằng cách nhấn Ctrl + X và nhập Y khi được nhắc.
Tạo và mở
Dán mã sau vào nó.
Lưu tệp bằng cách nhấn Ctrl + X và nhập Y khi được nhắc.
Tải lại daemon Systemctl.
Chạy các lệnh sau để bật và khởi động Seafile và Seahub dịch vụ.
Kiểm tra trạng thái của cả hai dịch vụ.
Tiếp theo, hãy kiểm tra trạng thái của Seahub.
Nhập khóa ký của Nginx.
Thêm kho lưu trữ cho phiên bản ổn định của Nginx.
Cập nhật hệ thống kho lưu trữ.
Cài đặt Nginx.
Xác minh cài đặt.
Khởi động máy chủ Nginx.
Ubuntu 22.04 đi kèm với Snapd được cài đặt theo mặc định. Chạy các lệnh sau để đảm bảo rằng phiên bản Snapd của bạn đã được cập nhật.
Cài đặt Certbot.
Sử dụng lệnh sau để đảm bảo rằng lệnh Certbot có thể chạy được bằng cách tạo liên kết tượng trưng đến
Chạy lệnh sau để tạo SSL Chứng chỉ.
Lệnh trên sẽ tải chứng chỉ xuống thư mục
Tạo nhóm Diffie-Hellman chứng chỉ.
Kiểm tra dịch vụ lập lịch gia hạn Certbot.
Bạn sẽ tìm thấy
Thực hiện chạy thử quy trình để kiểm tra xem việc gia hạn SSL có hoạt động không tốt.
Nếu bạn không thấy lỗi nào, bạn đã hoàn tất. Chứng chỉ của bạn sẽ tự động gia hạn.
Dán mã sau vào đó.
Lưu tệp bằng cách nhấn Ctrl + X và nhập Y khi được nhắc sau khi hoàn tất.
Mở tệp
Thêm dòng sau vào trước dòng
Lưu tệp bằng cách nhấn Ctrl + X và nhập Y khi được nhắc.
Xác minh tệp cấu hình Nginx cú pháp.
Khởi động lại dịch vụ Nginx.
data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22750%22%20height=%22389%22%3E%3C/svg%3E
Nhập thông tin đăng nhập bạn đã tạo ở bước 7 và nhấp vào nút Đăng nhập để tiếp tục. Bạn sẽ được chào đón bằng trang sau.
data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22750%22%20height=%22449%22%3E%3C/svg%3E
Nhấp vào Thư viện của tôi để mở thư viện mặc định.
data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22750%22%20height=%22449%22%3E%3C/svg%3E
Nhấp vào nút Tải lên và chọn tùy chọn Tải tệp lên. Chọn tệp bạn muốn tải lên và nhấp vào nút Mở.
Thanh tiến trình sẽ tải và tệp của bạn sẽ sớm được tải lên.
data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22750%22%20height=%22430%22%3E%3C/svg%3E
Để truy cập bảng Quản trị, hãy nhấp vào biểu tượng ảnh hồ sơ ở góc trên bên phải.
data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22312%22%20height=%22304%22%3E%3C/svg%3E
Chọn tùy chọn Quản trị hệ thống để mở bảng quản trị.
data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22750%22%20height=%22435%22%3E%3C/svg%3E
Từ đây trở đi, bạn có thể thay đổi thương hiệu của trang web, bật mật khẩu mạnh hơn và xác thực hai yếu tố, tắt đăng ký và quản lý nhiều người dùng cùng với các tùy chọn khác.
Trong hướng dẫn này, bạn sẽ học cách cài đặt Seafile trên máy chủ Ubuntu 22.04, MySQL và Nginx làm máy chủ proxy ngược.
Điều kiện tiên quyết
-
Máy chủ chạy Ubuntu 22.04 với tối thiểu 2 lõi CPU và 2GB RAM.
-
Người dùng không phải root có quyền sudo.
-
Tên miền đủ điều kiện (FQDN) nhưseafile.example.com
.
-
Đảm bảo mọi thứ đều được cập nhật.
Mã:
$ sudo apt update
$ sudo apt upgrade
Một số gói mà hệ thống của bạn cần.
Mã:
$ sudo apt install wget curl nano software-properties-common dirmngr apt-transport-https gnupg2 ca-certificates lsb-release ubuntu-keyring unzip -y
Bước 1 - Cấu hình Tường lửa
Bước đầu tiên là cấu hình tường lửa. Ubuntu đi kèm với ufw (Uncomplicated Firewall) theo mặc định.Kiểm tra xem tường lửa có đang chạy không.
Mã:
$ sudo ufw status
Mã:
Status: inactive
Mã:
$ sudo ufw allow OpenSSH
Mã:
$ sudo ufw allow http
$ sudo ufw allow https
Mã:
$ sudo ufw enable
Command may disrupt existing ssh connections. Proceed with operation (y|n)? y
Firewall is active and enabled on system startup
Mã:
$ sudo ufw status
Mã:
Status: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
80/tcp ALLOW Anywhere
443 ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
80/tcp (v6) ALLOW Anywhere (v6)
443 (v6) ALLOW Anywhere (v6)
Bước 2 - Cài đặt Seafile Dependencies
Vì Seafile được viết trong khuôn khổ Python Django, bạn cần cài đặt các phụ thuộc và gói Python để làm cho nó hoạt động.Chạy lệnh sau để cài đặt các công cụ Python, trình quản lý gói Pip, thư viện SQL và Memcached.
Mã:
$ sudo apt install -y python3 python3-setuptools python3-pip libmysqlclient-dev memcached libmemcached-dev
Mã:
$ sudo pip3 install --timeout=3600 django==3.2.* future==0.18.* mysqlclient==2.1.* \ pymysql pillow==9.3.* pylibmc captcha==0.4 markupsafe==2.0.1 jinja2 sqlalchemy==1.4.3 \ psd-tools django-pylibmc django_simple_captcha==0.5.* djangosaml2==1.5.* pysaml2==7.2.* pycryptodome==3.16.* cffi==1.15.1 lxml
Bước 3 - Cài đặt MySQL
Ubuntu Phiên bản 22.04 đi kèm với phiên bản MySQL mới nhất. Bạn có thể cài đặt bằng một lệnh duy nhất.
Mã:
$ sudo apt install -y mysql-server
Mã:
$ mysql --version
mysql Ver 8.0.32-0ubuntu0.22.04.2 for Linux on x86_64 ((Ubuntu))
Mã:
$ sudo mysql
Mã:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YourPassword12!';
Mã:
mysql> exit
Mã:
$ sudo mysql_secure_installation
Mã:
Securing the MySQL server deployment.
Enter password for user root:
VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?
Press y|Y for Yes, any other key for No: Y
There are three levels of password validation policy:
LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
Using existing password for root.
Estimated strength of the password: 100
Mã:
Change the password for root ? ((Press y|Y for Yes, any other key for No) : N ... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
Success.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
Success.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y - Dropping test database...
Success. - Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
Success.
All done!
Bước 4 - Cấu hình MySQL
Đăng nhập vào shell MySQL. Nhập mật khẩu gốc của bạn khi được nhắc.
Mã:
$ sudo mysql -u root -p
Mã:
mysql> CREATE DATABASE ccnet_db CHARACTER SET utf8;
mysql> CREATE DATABASE seafile_db CHARACTER SET utf8;
mysql> CREATE DATABASE seahub_db CHARACTER SET utf8;
mysql_native_password
và vì MySQL 8 không sử dụng plugin này theo mặc định, do đó bạn cần chỉ định plugin này khi tạo.
Mã:
mysql> CREATE USER 'seafile'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Your_password2';
Mã:
mysql> GRANT ALL PRIVILEGES ON `ccnet_db`.* to `seafile`@localhost;
mysql> GRANT ALL PRIVILEGES ON `seafile_db`.* to `seafile`@localhost;
mysql> GRANT ALL PRIVILEGES ON `seahub_db`.* to `seafile`@localhost;
Mã:
mysql> FLUSH PRIVILEGES;
Mã:
mysql> exit
Bước 5 - Tạo thư mục Seafile và người dùng
Tạo thư mục cho các tệp chương trình của Seafile.
Mã:
$ sudo mkdir /opt/seafile
Mã:
$ sudo adduser --home /opt/seafile --shell /bin/bash seafile
Mã:
$ sudo chown -R seafile: /opt/seafile
Bước 6 - Tải xuống và cài đặt Seafile
Đăng nhập với tư cách là người dùng Seafile. Nhập mật khẩu người dùng khi được nhắc.
Mã:
$ su seafile
Tải xuống kho lưu trữ máy chủ Seafile.
Mã:
$ wget https://s3.eu-central-1.amazonaws.com/download.seadrive.org/seafile-server_10.0.1_x86-64.tar.gz
Mã:
$ tar xf seafile-server_10.0.1_x86-64.tar.gz
Mã:
$ cd seafile-server-10.0.1/
Mã:
$ ./setup-seafile-mysql.sh
Mã:
Checking python on this machine ...
-----------------------------------------------------------------
This script will guide you to setup your seafile server using MySQL.
Make sure you have read seafile server manual at https://download.seafile.com/published/seafile-manual/home.md
Press ENTER to continue
-----------------------------------------------------------------
Mã:
What is the name of the server? It will be displayed on the client.
3 - 15 letters or digits
[ server name ] Howtoforge
What is the ip or domain of the server?
For example: www.mycompany.com, 192.168.1.101
[ This server's ip or domain ] seafile.example.com
Which port do you want to use for the seafile fileserver?
[ default "8082" ]
Mã:
-------------------------------------------------------
Please choose a way to initialize seafile databases:
-------------------------------------------------------
[1] Create new ccnet/seafile/seahub databases
[2] Use existing ccnet/seafile/seahub databases
[ 1 or 2 ] 2
Mã:
What is the host of mysql server?
[ default "localhost" ]
What is the port of mysql server?
[ default "3306" ]
Which mysql user to use for seafile?
[ mysql user for seafile ] seafile
What is the password for mysql user "seafile"?
[ password for seafile ]
verifying password of user seafile ... done
Enter the existing database name for ccnet:
[ ccnet database ] ccnet_db
verifying user "seafile" access to database ccnet_db ... done
Enter the existing database name for seafile:
[ seafile database ] seafile_db
verifying user "seafile" access to database seafile_db ... done
Enter the existing database name for seahub:
[ seahub database ] seahub_db
verifying user "seafile" access to database seahub_db ... done
Mã:
---------------------------------
This is your configuration
--------------------------------- server name: Howtoforge server ip/domain: seafile.example.com seafile data dir: /opt/seafile/seafile-data fileserver port: 8082 database: use existing ccnet database: ccnet_db seafile database: seafile_db seahub database: seahub_db database user: seafile
---------------------------------
Press ENTER to continue, or Ctrl-C to abort
---------------------------------
Mã:
Generating ccnet configuration ...
Generating seafile configuration ...
done
Generating seahub configuration ...
----------------------------------------
Now creating ccnet database tables ...
----------------------------------------
----------------------------------------
Now creating seafile database tables ...
----------------------------------------
----------------------------------------
Now creating seahub database tables ...
----------------------------------------
creating seafile-server-latest symbolic link ... done
-----------------------------------------------------------------
Your seafile server configuration has been finished successfully.
-----------------------------------------------------------------
run seafile server: ./seafile.sh { start | stop | restart }
run seahub server: ./seahub.sh { start
| stop | restart }
-----------------------------------------------------------------
If you are behind a firewall, remember to allow input/output of these tcp ports:
-----------------------------------------------------------------
port of seafile fileserver: 8082
port of seahub: 8000
When problems occur, Refer to https://download.seafile.com/published/seafile-manual/home.md
for information.
Bước 7 - Khởi động Seafile Server
Chuyển sang/opt/seafile/seafile-server-latest
thư mục.
Mã:
$ cd /opt/seafile/seafile-server-latest
Mã:
$ ./seafile.sh start
Mã:
Starting seafile server, please wait ...
** Message: 04:42:32.937: seafile-controller.c(621): No seafevents.
Seafile server started
Done.
Mã:
$ ./seahub.sh start
Mã:
LC_ALL is not set in ENV, set to en_US.UTF-8
Starting seahub at port 8000 ...
----------------------------------------
It's the first time you start the seafile server. Now let's create the admin account
----------------------------------------
What is the email for the admin account?
[ admin email ] [emailprotected]
What is the password for the admin account?
[ admin password ]
Enter the password again:
[ admin password again ]
----------------------------------------
Successfully created seafile admin
----------------------------------------
Seahub is started
Done.
Mã:
$ ./seafile.sh stop
$ ./seahub.sh stop
Bước 8 - Cấu hình Seafile
Mở tệp/opt/seafile/conf/seafile.conf
để chỉnh sửa.
Mã:
$ nano /opt/seafile/conf/seafile.conf
host = 127.0.0.1
bên dưới [fileserver]
phần.
Mã:
[fileserver]
host = 127.0.0.1
port = 8082
Mở tệp
/opt/seafile/conf/seahub_settings.py
để chỉnh sửa.
Mã:
$ nano /opt/seafile/conf/seahub_settings.py
SERVICE_URL
để phản ánh giao thức HTTPS.
Mã:
SERVICE_URL = "https://seafile.example.com/"
Mã:
FILE_SERVER_ROOT = "https://seafile.example.com/seafhttp"
Mã:
CACHES = { 'default': { 'BACKEND': 'django_pylibmc.memcached.PyLibMCCache', 'LOCATION': '127.0.0.1:11211', },
}
Thoát khỏi người dùng Seafile shell.
Mã:
$ exit
Bước 9 - Tạo dịch vụ Systemd
Để đảm bảo Seafile tự động khởi động khi khởi động và có thể chịu được các lần khởi động lại, bạn cần tạo các tệp đơn vị dịch vụ Systemd cho nó.Tạo và mở tệp
/etc/systemd/system/seafile.service
cho chỉnh sửa.
Mã:
$ sudo nano /etc/systemd/system/seafile.service
Mã:
[Unit]
Description=Seafile
# add mysql.service or postgresql.service depending on your database to the line below
After=network.target mysql.service
[Service]
Type=forking
ExecStart=/opt/seafile/seafile-server-latest/seafile.sh start
ExecStop=/opt/seafile/seafile-server-latest/seafile.sh stop
LimitNOFILE=infinity
User=seafile
Group=seafile
[Install]
WantedBy=multi-user.target
Tạo và mở
/etc/systemd/system/seahub.service
tệp để chỉnh sửa.
Mã:
$ sudo nano /etc/systemd/system/seahub.service
Mã:
[Unit]
Description=Seafile hub
After=network.target seafile.service
[Service]
Type=forking
# change start to start-fastcgi if you want to run fastcgi
ExecStart=/opt/seafile/seafile-server-latest/seahub.sh start
ExecStop=/opt/seafile/seafile-server-latest/seahub.sh stop
User=seafile
Group=seafile
[Install]
WantedBy=multi-user.target
Tải lại daemon Systemctl.
Mã:
$ sudo systemctl daemon-reload
Mã:
$ sudo systemctl enable --now seafile
$ sudo systemctl enable --now seahub
Mã:
$ sudo systemctl status seafile
? seafile.service - Seafile Loaded: loaded (/etc/systemd/system/seafile.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2023-04-19 07:20:38 UTC; 24s ago Tasks: 19 (limit: 1026) Memory: 11.6M CPU: 102ms CGroup: /system.slice/seafile.service ??3601 /opt/seafile/seafile-server-10.0.1/seafile/bin/seafile-controller -c /opt/seafile/ccnet -d /opt/seafile/seafile-data -F /opt/seafile/conf
Mã:
$ sudo systemctl status seahub
? seahub.service - Seafile hub Loaded: loaded (/etc/systemd/system/seahub.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2023-04-19 07:20:54 UTC; 19s ago Process: 3655 ExecStart=/opt/seafile/seafile-server-latest/seahub.sh start (code=exited, status=0/SUCCESS) Main PID: 3668 (python3) Tasks: 6 (limit: 1026) Memory: 85.8M CPU: 1.177s CGroup: /system.slice/seahub.service ??3668 python3 /opt/seafile/seafile-server-10.0.1/seahub/thirdpart/bin/gunicorn seahub.wsgi:application -c /opt/seafile/conf/gunicorn.conf.py --preload
Bước 10 - Cài đặt Nginx
Ubuntu 22.04 đi kèm với phiên bản Nginx cũ hơn. Để cài đặt phiên bản mới nhất, bạn cần tải xuống kho lưu trữ Nginx chính thức.Nhập khóa ký của Nginx.
Mã:
$ curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
| sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
Mã:
$ echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg arch=amd64] \
http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" \
| sudo tee /etc/apt/sources.list.d/nginx.list
Mã:
$ sudo apt update
Mã:
$ sudo apt install nginx
Mã:
$ nginx -v
nginx version: nginx/1.24.0
Mã:
$ sudo systemctl start nginx
Bước 11 - Cài đặt SSL
Chúng ta cần cài đặt Certbot để tạo chứng chỉ SSL. Bạn có thể cài đặt Certbot bằng kho lưu trữ của Ubuntu hoặc tải phiên bản mới nhất bằng công cụ Snapd. Chúng tôi sẽ sử dụng phiên bản Snapd.Ubuntu 22.04 đi kèm với Snapd được cài đặt theo mặc định. Chạy các lệnh sau để đảm bảo rằng phiên bản Snapd của bạn đã được cập nhật.
Mã:
$ sudo snap install core && sudo snap refresh core
Mã:
$ sudo snap install --classic certbot
/usr/bin
thư mục.
Mã:
$ sudo ln -s /snap/bin/certbot /usr/bin/certbot
Mã:
$ sudo certbot certonly --nginx --agree-tos --no-eff-email --staple-ocsp --preferred-challenges http -m [emailprotected] -d seafile.example.com
/etc/letsencrypt/live/seafile.example.com
trên máy chủ của bạn.Tạo nhóm Diffie-Hellman chứng chỉ.
Mã:
$ sudo openssl dhparam -dsaparam -out /etc/ssl/certs/dhparam.pem 4096
Mã:
$ sudo systemctl list-timers
snap.certbot.renew.service
là một trong những dịch vụ được lên lịch chạy.
Mã:
NEXT LEFT LAST PASSED UNIT ACTIVATES
Wed 2023-04-19 10:31:47 UTC 2h 55min left Wed 2023-04-19 03:31:58 UTC 4h 3min ago ua-timer.timer ua-timer.service
Wed 2023-04-19 12:02:42 UTC 4h 26min left Wed 2023-04-19 03:19:20 UTC 4h 16min ago motd-news.timer motd-news.service
Wed 2023-04-19 18:19:56 UTC 10h left Wed 2023-04-19 07:19:52 UTC 16min ago apt-daily.timer apt-daily.service
Wed 2023-04-19 22:51:00 UTC 15h left n/a n/a snap.certbot.renew.timer snap.certbot.renew.service
Mã:
$ sudo certbot renew --dry-run
Bước 12 - Cấu hình Nginx
Tạo và mở tệp/etc/nginx/conf.d/seafile.conf
để chỉnh sửa.
Mã:
$ sudo nano /etc/nginx/conf.d/seafile.conf
Mã:
log_format seafileformat '$http_x_forwarded_for $remote_addr [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $upstream_response_time';
server { listen 80; listen [::]:80; server_name seafile.example.com; rewrite ^ https://$http_host$request_uri? permanent; # Forced redirect from HTTP to HTTPS server_tokens off; # Prevents the Nginx version from being displayed in the HTTP response header
}
server { listen 443 ssl http2; listen [::]:443 ssl http2; ssl_certificate /etc/letsencrypt/live/seafile.example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/seafile.example.com/privkey.pem; ssl_trusted_certificate /etc/letsencrypt/live/seafile.example.com/chain.pem; ssl_session_timeout 5m; ssl_session_cache shared:MozSSL:10m; ssl_session_tickets off; ssl_protocols TLSv1.2 TLSv1.3; ssl_prefer_server_ciphers on; ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384; ssl_ecdh_curve X25519:prime256v1:secp384r1:secp521r1; ssl_stapling on; ssl_stapling_verify on; ssl_dhparam /etc/ssl/certs/dhparam.pem; resolver 8.8.8.8; server_name seafile.example.com; server_tokens off; location / { proxy_pass http://127.0.0.1:8000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Host $server_name; proxy_read_timeout 1200s; proxy_set_header X-Forwarded-Proto https; # used for view/edit office file via Office Online Server client_max_body_size 0; access_log /var/log/nginx/seahub.access.log seafileformat; error_log /var/log/nginx/seahub.error.log; } location /seafhttp { rewrite ^/seafhttp(.*)$ $1 break; proxy_pass http://127.0.0.1:8082; client_max_body_size 0; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_connect_timeout 36000s; proxy_read_timeout 36000s; proxy_send_timeout 36000s; send_timeout 36000s; # Uncomment the following line if you want to support uploads > 4GB # proxy_request_buffering off; access_log /var/log/nginx/seafhttp.access.log seafileformat; error_log /var/log/nginx/seafhttp.error.log; } location /media { root /opt/seafile/seafile-server-latest/seahub; }
}
Mở tệp
/etc/nginx/nginx.conf
để chỉnh sửa.
Mã:
$ sudo nano /etc/nginx/nginx.conf
include /etc/nginx/conf.d/*.conf;
.
Mã:
server_names_hash_bucket_size 64;
Xác minh tệp cấu hình Nginx cú pháp.
Mã:
$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Mã:
$ sudo systemctl restart nginx
Bước 13 - Truy cập Seafile
Mở URLhttps://seafile.example.com
trong trình duyệt của bạn và bạn sẽ nhận được màn hình đăng nhập sau.data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22750%22%20height=%22389%22%3E%3C/svg%3E
Nhập thông tin đăng nhập bạn đã tạo ở bước 7 và nhấp vào nút Đăng nhập để tiếp tục. Bạn sẽ được chào đón bằng trang sau.
data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22750%22%20height=%22449%22%3E%3C/svg%3E
Nhấp vào Thư viện của tôi để mở thư viện mặc định.
data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22750%22%20height=%22449%22%3E%3C/svg%3E
Nhấp vào nút Tải lên và chọn tùy chọn Tải tệp lên. Chọn tệp bạn muốn tải lên và nhấp vào nút Mở.
Thanh tiến trình sẽ tải và tệp của bạn sẽ sớm được tải lên.
data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22750%22%20height=%22430%22%3E%3C/svg%3E
Để truy cập bảng Quản trị, hãy nhấp vào biểu tượng ảnh hồ sơ ở góc trên bên phải.
data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22312%22%20height=%22304%22%3E%3C/svg%3E
Chọn tùy chọn Quản trị hệ thống để mở bảng quản trị.
data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22750%22%20height=%22435%22%3E%3C/svg%3E
Từ đây trở đi, bạn có thể thay đổi thương hiệu của trang web, bật mật khẩu mạnh hơn và xác thực hai yếu tố, tắt đăng ký và quản lý nhiều người dùng cùng với các tùy chọn khác.