我必须接管一个内部Web服务器,这个服务器是由一个已经不在那里的同事配置的。我们的开发团队要求我将应用程序url从别名转换为Virtualhosts(子域名命名)系统。例如:
https://srv-intra.mydomain.fr/basecolldev应该成为https://basecolldev.mydomain.fr
环境规范:
- Linux OpenSUSE Leap 15.3
- 服务器版本:Apache/2.4.51 (Linux/SUSE)
- PHP 7.4.6 (cli) (NTS)
问题描述:我可以连接到https://basecolldev.mydomain.fr
,尽管一些404错误显示在access_log文件(见在帖子的末尾)。当我点击重定向到https://basecolldev.mydomain.fr/login
的登录按钮时,我有一个404错误页面。手动修改URL为"https://basecolldev.mydomain.fr/index.php/login
",可以找到并正常显示登录页面。这意味着/index.php
不需要用于主页连接,而是用于浏览网站。我需要永久防止/index.php
后缀出现在URL中。
我将在下面描述到目前为止我已经配置的内容以及仍然无法正常工作的内容。
我首先创建了一个新的vhost文件/etc/apache2/vhost.d/basecolldev-ssl.conf
:
<VirtualHost basecolldev.mydomain.fr:443>
DocumentRoot "/var/www/BaseCollDev/public"
ServerName basecolldev.mydomain.fr
ErrorLog /var/log/apache2/basecolldev-error_log
TransferLog /var/log/apache2/basecolldev-access_log
LogLevel alert rewrite:trace8
<Directory /var/www/BaseCollDev/public>
#Order allow,deny
#allow from all
#AllowOverride All
Require all granted
Options -Indexes -Includes -ExecCGI -FollowSymlinks
</Directory>
</VirtualHost>
然后在文件/etc/apache2/default-server.conf
:
Directory
标记相关的行DocumentRoot "/var/www"
<Directory "/var/www">
Options FollowSymLinks
AllowOverride None
<IfModule !mod_access_compat.c>
Require all granted
</IfModule>
<IfModule mod_access_compat.c>
Order allow,deny
Allow from all
</IfModule>
</Directory>
Alias /icons/ "/usr/share/apache2/icons/"
Alias /phpmyadmin "/srv/www/htdocs/phpMyAdmin"
<Directory "/usr/share/apache2/icons">
Options Indexes MultiViews
AllowOverride None
<IfModule !mod_access_compat.c>
Require all granted
</IfModule>
<IfModule mod_access_compat.c>
Order allow,deny
Allow from all
</IfModule>
</Directory>
#<Directory "/var/www/BaseCollDev/public">
# AllowOverride All
# Require all granted
#</Directory>
ScriptAlias /cgi-bin/ "/srv/www/cgi-bin/"
<Directory "/srv/www/cgi-bin">
AllowOverride None
Options +ExecCGI -Includes
<IfModule !mod_access_compat.c>
Require all granted
</IfModule>
<IfModule mod_access_compat.c>
Order allow,deny
Allow from all
</IfModule>
</Directory>
<IfModule mod_userdir.c>
UserDir public_html
Include /etc/apache2/mod_userdir.conf
</IfModule>
IncludeOptional /etc/apache2/conf.d/*.conf
IncludeOptional /etc/apache2/conf.d/apache2-manual?conf
从/var/log/apache2/basecolldev-access_log
文件中提取与主页连接有关的内容:
10.9.4.140 - - [03/Jun/2022:11:02:31 +0200] "GET / HTTP/1.1" 200 54206
10.9.4.140 - - [03/Jun/2022:11:02:31 +0200] "GET /build/runtime.d94b3b43.js HTTP/1.1" 200 1505
10.9.4.140 - - [03/Jun/2022:11:02:31 +0200] "GET /build/app.13d64c6c.js HTTP/1.1" 200 236
10.9.4.140 - - [03/Jun/2022:11:02:31 +0200] "GET /build/2.9935185b.css HTTP/1.1" 200 64639
10.9.4.140 - - [03/Jun/2022:11:02:31 +0200] "GET /build/app.6cefaab5.css HTTP/1.1" 200 163752
10.9.4.140 - - [03/Jun/2022:11:02:31 +0200] "GET /build/2.28b18d57.js HTTP/1.1" 200 261268
10.9.4.140 - - [03/Jun/2022:11:02:31 +0200] "GET /build/images/logoEdVBlanc.png HTTP/1.1" 200 6579
10.9.4.140 - - [03/Jun/2022:11:02:31 +0200] "GET /_wdt/b07606 HTTP/1.1" 404 1280
10.9.4.140 - - [03/Jun/2022:11:02:31 +0200] "GET /build/fonts/fa-solid-900.e8a427e1.woff2 HTTP/1.1" 200 78196
10.9.4.140 - - [03/Jun/2022:11:02:32 +0200] "GET /favicon.ico HTTP/1.1" 404 1280
10.9.4.140 - - [03/Jun/2022:11:02:32 +0200] "GET /_wdt/b07606 HTTP/1.1" 404 1280
10.9.4.140 - - [03/Jun/2022:11:02:33 +0200] "GET /_wdt/b07606 HTTP/1.1" 404 1280
10.9.4.140 - - [03/Jun/2022:11:02:34 +0200] "GET /_wdt/b07606 HTTP/1.1" 404 1280
10.9.4.140 - - [03/Jun/2022:11:02:35 +0200] "GET /_wdt/b07606 HTTP/1.1" 404 1280
从连接到登录页面的/var/log/apache2/basecolldev-access_log
文件中提取:
10.9.4.140 - - [03/Jun/2022:11:03:47 +0200] "GET /login HTTP/1.1" 404 1280
我在/var/log/apache2/basecolldev-error_log
文件中没有看到日志。
必要时附上.htaccess
文件内容。
File/var/www/.htaccess
:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
File/var/www/BaseCollDev/public/.htaccess
:
DirectoryIndex index.php
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$0 ^(/.+)/(.*)::2$
RewriteRule .* - [E=BASE:%1]
RewriteCond %{HTTP:Authorization} .+
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%0]
RewriteCond %{ENV:REDIRECT_STATUS} =""
RewriteRule ^index.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ %{ENV:BASE}/index.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 307 ^/$ /index.php/
</IfModule>
</IfModule>
您的<Directory "/var/www">
中有AllowOverride None
。这意味着没有读取.htaccess
文件,因此也没有读取mod_rewrite配置。最简单的选项是AllowOverride All
(如果您愿意,也可以指定特定的覆盖)。
您还需要允许以下符号链接(删除-FollowSymlinks
,可能添加+FollowSymlinks
)。
我最终使它能够正常工作,我这样做了:
文件/etc/apache2/default-server.conf
>changeAllow Override
toAll
:
<Directory "/var/www">
...
AllowOverride All
...
</Directory>
文件/etc/apache2/vhosts.d/basecoll-ssl.conf
>删除-FollowSymlinks
选项:
<VirtualHost basecolldev.mydomain.fr:443>
...
<Directory /var/www/BaseCollDev/public>
...
Options -Indexes -Includes -ExecCGI
...
</Directory>
</VirtualHost>
谢谢你的帮助,让我走上正确的道路!
使用AliasMatch代替Alias:
AliasMatch ^/bar/?(.*) /var/www/bar/$1