> 文章列表 > Nextcloud去掉URL中的index.php以及强制https(Win10子系统WSL)

Nextcloud去掉URL中的index.php以及强制https(Win10子系统WSL)

Nextcloud去掉URL中的index.php以及强制https(Win10子系统WSL)

一、Nextcloud去掉URL中的index.php

1、启用相关模块

cd /var/www/nextcloud   #进入程序目录sudo chmod -R 777 .htaccess  #设置.htaccess文件权限可读写sudo a2enmod envaudo 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
# 在配置文件中增加以下内容
<Directory /var/www/nextcloud/> Require all granted AllowOverride All Options FollowSymLinks MultiViews
</Directory>

Nextcloud去掉URL中的index.php以及强制https(Win10子系统WSL)

注意事项

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

<VirtualHost *:80>DocumentRoot /var/www/nextcloudServerName 192.168.1.1Alias /nextcloud "/var/www/nextcloud"ErrorLog ${APACHE_LOG_DIR}/nextcloud.errorCustomLog ${APACHE_LOG_DIR}/nextcloud.access combined<Directory /var/www/nextcloud/>
#       		Require all granted
#       		Options FollowSymlinks MultiViews
#       		AllowOverride All
#       		DirectoryIndex index.php index.htm index.html
#      <IfModule mod_dav.c>Dav off</IfModule>SetEnv HOME /var/www/nextcloudSetEnv HTTP_HOME /var/www/nextcloudSatisfy Any</Directory></VirtualHost>

(2)https访问配置

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

Nextcloud去掉URL中的index.php以及强制https(Win10子系统WSL)

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

Nextcloud去掉URL中的index.php以及强制https(Win10子系统WSL)