Nextcloud 之 Selinux

来源:

https://docs.nextcloud.com/server/14/admin_manual/installation/selinux_configuration.html


When you have SELinux enabled on your Linux distribution, you may run into permissions problems after a new Nextcloud installation, and see permission denied errors in your Nextcloud logs.

The following settings should work for most SELinux systems that use the default distro profiles. Run these commands as root, and remember to adjust the filepaths in these examples for your installation:

semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/nextcloud/data(/. * )?'
semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/nextcloud/config(/. * )?'
semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/nextcloud/apps(/. * )?'
semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/nextcloud/.htaccess'
semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/nextcloud/.user.ini'

restorecon -Rv '/var/www/html/nextcloud/'


If you uninstall Nextcloud you need to remove the Nextcloud directory labels. To do this execute the following commands as root after uninstalling Nextcloud:

semanage fcontext -d '/var/www/html/nextcloud/data(/.*)?'
semanage fcontext -d '/var/www/html/nextcloud/config(/.*)?'
semanage fcontext -d '/var/www/html/nextcloud/apps(/.*)?'
semanage fcontext -d '/var/www/html/nextcloud/.htaccess'
semanage fcontext -d '/var/www/html/nextcloud/.user.ini'

restorecon -Rv '/var/www/html/nextcloud/'

If you have customized SELinux policies and these examples do not work, you must give the HTTP server write access to these directories:

/var/www/html/nextcloud/data
/var/www/html/nextcloud/config
/var/www/html/nextcloud/apps

Enable updates via the web interface
To enable updates via the web interface, you may need this to enable writing to the directories:

setsebool httpd_unified on

When the update is completed, disable write access:

setsebool -P  httpd_unified  off

Disallow write access to the whole web directory
For security reasons it’s suggested to disable write access to all folders in /var/www/ (default):

setsebool -P  httpd_unified  off

Allow access to a remote database
An additional setting is needed if your installation is connecting to a remote database:

setsebool -P httpd_can_network_connect_db on

Allow access to LDAP server
Use this setting to allow LDAP connections:

setsebool -P httpd_can_connect_ldap on

Allow access to remote network
Nextcloud requires access to remote networks for functions such as Server-to-Server sharing, external storages or the app store. To allow this access use the following setting:

setsebool -P httpd_can_network_connect on

Allow access to network memcache
This setting is not required if httpd_can_network_connect is already on:

setsebool -P httpd_can_network_memcache on

Allow access to SMTP/sendmail
If you want to allow Nextcloud to send out e-mail notifications via sendmail you need to use the following setting:

setsebool -P httpd_can_sendmail on

Allow access to CIFS/SMB
If you have placed your datadir on a CIFS/SMB share use the following setting:

setsebool -P httpd_use_cifs on

Allow access to FuseFS
If your data folder resides on a Fuse Filesystem (e.g. EncFS etc), this setting is required as well:

setsebool -P httpd_use_fusefs on

Allow access to GPG for Rainloop
If you use a the rainloop webmail client app which supports GPG/PGP, you might need this:

setsebool -P httpd_use_gpg on

Troubleshooting
For general Troubleshooting of SELinux and its profiles try to install the package setroubleshoot and run:

sealert -a /var/log/audit/audit.log > /path/to/mylogfile.txt

to get a report which helps you configuring your SELinux profiles.

Another tool for troubleshooting is to enable a single ruleset for your Nextcloud directory:

semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/nextcloud(/.*)?'
restorecon -RF /var/www/html/nextcloud

It is much stronger security to have a more fine-grained ruleset as in the examples at the beginning, so use this only for testing and troubleshooting. It has a similar effect to disabling SELinux, so don’t use it on production systems.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
安装 Nextcloud: 1. 安装 LAMP 或 LEMP 环境(推荐使用 LEMP) ```bash # 安装 epel-release 和 nginx sudo dnf install -y epel-release sudo dnf install -y nginx # 安装 MariaDB sudo dnf install -y mariadb-server mariadb # 启动 MariaDB sudo systemctl start mariadb # 设置 MariaDB 开机自启 sudo systemctl enable mariadb # 运行 MySQL 安全策略 sudo mysql_secure_installation # 安装 PHP-FPM 和相关的扩展 sudo dnf install -y php-fpm php-opcache php-gd php-mysqlnd php-json php-mbstring php-xml php-zip php-intl php-curl ``` 2. 安装 Nextcloud ```bash # 添加 Nextcloud 的存储库 sudo dnf install -y https://download.nextcloud.com/server/releases/nextcloud-22.2.0-1.noarch.rpm # 安装 Nextcloud sudo dnf install -y nextcloud # 配置 SELinux sudo setsebool -P httpd_can_network_connect_db 1 # 配置 Nginx sudo cp /usr/share/doc/nextcloud-22.2.0-1/nginx.example.conf /etc/nginx/conf.d/nextcloud.conf sudo vi /etc/nginx/conf.d/nextcloud.conf # 在 server {} 块中添加以下内容 location /nextcloud { alias /usr/share/webapps/nextcloud/; try_files $uri $uri/ /nextcloud/index.php?$query_string; 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/.+|core/templates/40[34])\.php(?:$|/) { fastcgi_split_path_info ^(.+\.php)(/.*)$; try_files $fastcgi_script_name =404; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param HTTPS on; fastcgi_param modHeadersAvailable true; fastcgi_param front_controller_active true; fastcgi_pass unix:/run/php-fpm/www.sock; fastcgi_intercept_errors on; fastcgi_request_buffering off; fastcgi_read_timeout 300; } } # 重新加载 Nginx 配置 sudo systemctl reload nginx # 配置数据库 sudo mysql -u root -p CREATE DATABASE nextcloud; CREATE USER 'nextcloud'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextcloud'@'localhost'; FLUSH PRIVILEGES; exit # 初始化 Nextcloud sudo -u http /usr/bin/php /usr/share/webapps/nextcloud/occ maintenance:install --database "mysql" --database-name "nextcloud" --database-user "nextcloud" --database-pass "password" --admin-user "admin" --admin-pass "password" ``` 3. 配置 HTTPS ```bash # 安装 Certbot sudo dnf install -y certbot python3-certbot-nginx # 获取证书 sudo certbot --nginx -d example.com # 自动更新证书 sudo vi /etc/crontab # 在最后添加以下内容 0 0 1 * * root /usr/bin/certbot renew --quiet && systemctl reload nginx ``` 安装 OnlyOffice: 1. 安装 Docker ```bash # 安装 Docker sudo dnf install -y dnf-plugins-core sudo dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo sudo dnf install -y docker-ce docker-ce-cli containerd.io # 启动 Docker sudo systemctl start docker # 设置 Docker 开机自启 sudo systemctl enable docker ``` 2. 安装 OnlyOffice ```bash # 创建目录 sudo mkdir -p /app/onlyoffice/DocumentServer/data # 创建 Docker 网络 sudo docker network create onlyoffice # 运行 OnlyOffice sudo docker run -i -t -d --restart=always --network=onlyoffice --name onlyoffice-document-server -v /app/onlyoffice/DocumentServer/data:/var/www/onlyoffice/Data onlyoffice/documentserver:latest # 配置 Nginx 反向代理 sudo vi /etc/nginx/conf.d/onlyoffice.conf # 添加以下内容 upstream onlyoffice { server 127.0.0.1:80; } server { listen 80; server_name onlyoffice.example.com; # Redirect all HTTP requests to HTTPS with a 301 Moved Permanently response. return 301 https://$host$request_uri; } server { listen 443 ssl http2; server_name onlyoffice.example.com; # SSL configuration ssl_certificate /etc/letsencrypt/live/onlyoffice.example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/onlyoffice.example.com/privkey.pem; # SSL session caching ssl_session_cache shared:SSL:10m; ssl_session_timeout 5m; # SSL security ssl_protocols TLSv1.2 TLSv1.3; # OnlyOffice proxy location / { proxy_pass http://onlyoffice; proxy_redirect off; 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-Proto $scheme; } } # 重新加载 Nginx 配置 sudo systemctl reload nginx ``` 3. 配置 Nextcloud ```bash # 安装 OnlyOffice 应用 sudo -u http php /usr/share/webapps/nextcloud/occ app:install onlyoffice # 配置 OnlyOffice sudo -u http php /usr/share/webapps/nextcloud/occ config:app:set onlyoffice DocumentServerUrl --value="https://onlyoffice.example.com" sudo -u http php /usr/share/webapps/nextcloud/occ config:app:set onlyoffice DocumentServerInternalUrl --value="http://onlyoffice" sudo -u http php /usr/share/webapps/nextcloud/occ config:app:set onlyoffice StorageUrl --value="/nextcloud/remote.php/webdav/" sudo -u http php /usr/share/webapps/nextcloud/occ config:app:set onlyoffice StorageUrl --value="/nextcloud/remote.php/webdav/" sudo -u http php /usr/share/webapps/nextcloud/occ config:app:set onlyoffice DisableConfig --value="false" sudo -u http php /usr/share/webapps/nextcloud/occ config:app:set onlyoffice ForceSave --value="true" sudo -u http php /usr/share/webapps/nextcloud/occ config:app:set onlyoffice Secret --value="secret" sudo -u http php /usr/share/webapps/nextcloud/occ config:app:set onlyoffice JWTSecret --value="jwtsecret" sudo -u http php /usr/share/webapps/nextcloud/occ config:app:set onlyoffice JWTHeader --value="Authorization" sudo -u http php /usr/share/webapps/nextcloud/occ config:app:set onlyoffice VerifyPeerOff --value="true" ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值