一、Nextcloud去掉URL中的index.php

1、启用相关模块

cd /var/www/nextcloud #进入程序目录

sudo chmod -R 777 .htaccess #设置.htaccess文件权限可读写

sudo a2enmod env

audo a2enmod rewrite #启用rewrite模块

2、修改nextcloud配置文件

vim /var/www/nextcloud/config/config.php

# 在配置文件中添加以下参数

'overwrite.cli.url' => 'http://test.com:1234',

'htaccess.RewriteBase' => '/',

overwrite.cli.url后面设置为你的访问域名;

htaccess.RewriteBase后面设置为你的网站目录;(如果你的网站目录就是nextcloud,那么就是/,如果是下面的子目录,那么就是/子目录名)

3、开启apached的Rewrite模块

(1)http访问配置

vim /etc/apache2/apache2.conf

# 在配置文件中增加以下内容

Require all granted

AllowOverride All

Options FollowSymLinks MultiViews

注意事项

​ 本人在/etc/apache2/sites-available目录下增加了针对nextcloud的配置文件“nextcloud.conf”,在其中增加上述代码,但不生效,不知是何原因,之前是搞.net开发的,apache不熟悉。 最终还是把上述代码加到apache2的根配置文件中。

DocumentRoot /var/www/nextcloud

ServerName 192.168.1.1

Alias /nextcloud "/var/www/nextcloud"

ErrorLog ${APACHE_LOG_DIR}/nextcloud.error

CustomLog ${APACHE_LOG_DIR}/nextcloud.access combined

# Require all granted

# Options FollowSymlinks MultiViews

# AllowOverride All

# DirectoryIndex index.php index.htm index.html

#

Dav off

SetEnv HOME /var/www/nextcloud

SetEnv HTTP_HOME /var/www/nextcloud

Satisfy Any

(2)https访问配置

vim /etc/apache2/sites-available/default-ssl.conf

4、更新.htaccess文件

sudo -u www-data php /var/www/nextcloud/occ maintenance:update:htaccess

(1)报错

An unhandled exception has been thrown: Doctrine\DBAL\Exception: Failed to connect to the database: An exception occurred in the driver: could not find driver in /var/www/nextcloud/lib/private/DB/Connection.php:139

问题原因

安装了多个PHP,有php7.4、php8.0,未指定以哪个版本运行。

解决方法

# 解决方法:指定php版本

sudo -u www-data php8.0 occ maintenance:update:htaccess

(2)报错

An unhandled exception has been thrown: OCP\HintException: [0]: Memcache \OC\Memcache\APCu not available for local cache (Is the matching PHP module installed and enabled?)

解决方法

# 解决方法:在php.ini文件末尾加上:apc.enable_cli=1

vim /etc/php/8.0/cli/php.ini

5、重启apache2

sudo apachectl configtest #检查apache2配置

sudo service apache2 reload #重新加载配置

sudo service apache2 restart #重启apache2

6、刷新网页

刷新网页,url中已经没有index.php了。

参考博文:https://www.frank9.com/pretty-urls-for-nextcloud.html

二、http强制转https

vim /var/www/nextcloud/config/config.php

添加一下代码: ‘overwriteprotocol’ => ‘https’,

重启apache2

sudo service apache2 restart #重启apache2

注意: 如果使用的是非80端口且是自建的https证书,不建议启用HSTS功能。 因为启用HSTS后,浏览器不允许使用 HTTP 连接到 Nextcloud 实例,并试图防止站点访问者绕过无效证书警告。

文章链接

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: