1

注意:我读过的很多帖子都在谈论 httpd,这误导了我,有人告诉我,现代 Apache 不使用 httpd.conf 文件,而是使用自己的 apache2.conf

我已经在带有 debian 的 vps 上安装了 apache

我已发出以下命令

sudo a2enmod speling
sudo service apache2 restart
cd /etc/apache2/sites-available
sudo a2ensite 000-default
sudo service apache2 restart

如果我尝试在我的/etc/apache2/apache2.conf特别本节中将 AllowOverride 从 None 更改为 All

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

我在浏览器中收到以下错误?http://www.mumti.com/indeX.HtmL

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at webmaster@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.
Apache/2.4.25 (Debian) Server at www.mumti.com Port 80

这是 /etc/apache2/sites-available/000-default.conf 的副本

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    ServerName www.mumti.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf


</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

这是我的/var/www/.htaccess的副本,我不知道它是否生效,你怎么知道?

#
# 20200311
# https://www.a2hosting.com/kb/developer-corner/apache-web-server/using-the-mod-speling-apache-module
# AllowOverride All

#<Directory />
#   Options Indexes FollowSymLinks
#   AllowOverride All
#   Require all granted
#</Directory>


# https://stackoverflow.com/questions/17223855/how-would-i-make-apache-case-insensitive-using-htaccess
# 20200310
RewriteEngine on
CheckSpelling on

# https://www.a2hosting.com/kb/developer-corner/apache-web-server/using-the-mod-speling-apache-module
<IfModule mod_speling.c>
    CheckCaseOnly on
    CheckSpelling on
</IfModule>

有人说根本不要使用 .htaccess,我对此很好。/etc/apache2/sites-available/000-default.conf请告诉我如何通过或/etc/apache2/apache2.conf单独实现问题的标题。

我希望能够以任何拼写请求域的 URL,无论它是文件还是目录

感谢所有贡献者和这个伟大的网站。

更新:关于error.log的更多信息请求,好的,我找到了这个文件所在的位置。这是 /var/log/apache/error.log 的尾部

[Wed Mar 11 18:59:50.815205 2020] [mpm_event:notice] [pid 3281:tid 140482295300160] AH00489: Apache/2.4.25 (Debian) configured -- resuming normal operations
[Wed Mar 11 18:59:50.815277 2020] [core:notice] [pid 3281:tid 140482295300160] AH00094: Command line: '/usr/sbin/apache2'
[Wed Mar 11 18:59:56.596612 2020] [core:alert] [pid 3283:tid 140482088769280] [client 24.20.17.209:24867] /var/www/.htaccess: <Directory not allowed here
[Wed Mar 11 18:59:59.797563 2020] [core:alert] [pid 3283:tid 140482097161984] [client 24.20.17.209:24872] /var/www/.htaccess: <Directory not allowed here
[Wed Mar 11 19:00:02.115843 2020] [core:alert] [pid 3283:tid 140482080376576] [client 24.20.17.209:24877] /var/www/.htaccess: <Directory not allowed here
[Wed Mar 11 19:02:09.976967 2020] [core:alert] [pid 3282:tid 140482122340096] [client 24.20.17.209:25087] /var/www/.htaccess: <Directory not allowed here
[Wed Mar 11 19:02:11.213632 2020] [core:alert] [pid 3282:tid 140482113947392] [client 24.20.17.209:25090] /var/www/.htaccess: <Directory not allowed here
[Wed Mar 11 19:02:26.878673 2020] [core:alert] [pid 3282:tid 140482105554688] [client 24.20.17.209:25119] /var/www/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
[Wed Mar 11 19:02:28.125043 2020] [core:alert] [pid 3282:tid 140482097161984] [client 24.20.17.209:25122] /var/www/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
[Wed Mar 11 19:02:29.623182 2020] [core:alert] [pid 3282:tid 140482088769280] [client 24.20.17.209:25126] /var/www/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
[Wed Mar 11 19:02:32.544649 2020] [mpm_event:notice] [pid 3281:tid 140482295300160] AH00491: caught SIGTERM, shutting down
[Wed Mar 11 19:02:32.636398 2020] [mpm_event:notice] [pid 3361:tid 139631042101312] AH00489: Apache/2.4.25 (Debian) configured -- resuming normal operations
[Wed Mar 11 19:02:32.636474 2020] [core:notice] [pid 3361:tid 139631042101312] AH00094: Command line: '/usr/sbin/apache2'
[Wed Mar 11 19:02:36.250353 2020] [core:alert] [pid 3363:tid 139630838007552] [client 24.20.17.209:25137] /var/www/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
[Wed Mar 11 19:02:37.400118 2020] [core:alert] [pid 3363:tid 139630829614848] [client 24.20.17.209:25141] /var/www/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
[Wed Mar 11 19:02:38.932964 2020] [core:alert] [pid 3363:tid 139630821222144] [client 24.20.17.209:25144] /var/www/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
[Wed Mar 11 19:04:54.443494 2020] [mpm_event:notice] [pid 3361:tid 139631042101312] AH00491: caught SIGTERM, shutting down

请记住,您可以指示我配置实现目标所需的任何最低设置。除了配置文件上面的小调整尝试与前几天晚上 apache 的默认安装非常接近。谢谢。

另外,为什么我会收到此回复?

admin@VRR:~$ sudo service apache2 restart
: invalid option-
history: usage: history [-c] [-d offset] [n] or history -anrw [filename] or history -ps arg [arg...]
admin@VRR:~$

我在建议的答案中应用了@MrWite 000-default.conf 的建议模板,但sudo service apache2 restart上面的投诉仍然存在?无效选项??这是最近的error.log(我最近擦除了它)。

[Wed Mar 11 21:47:47.515090 2020] [mpm_event:notice] [pid 3621:tid 140717672165440] AH00489: Apache/2.4.25 (Debian) configured -- resuming normal operations
[Wed Mar 11 21:47:47.515169 2020] [core:notice] [pid 3621:tid 140717672165440] AH00094: Command line: '/usr/sbin/apache2'
[Wed Mar 11 21:59:14.795332 2020] [mpm_event:notice] [pid 3621:tid 140717672165440] AH00491: caught SIGTERM, shutting down
[Wed Mar 11 21:59:14.895378 2020] [mpm_event:notice] [pid 3716:tid 140701491482688] AH00489: Apache/2.4.25 (Debian) configured -- resuming normal operations
[Wed Mar 11 21:59:14.895455 2020] [core:notice] [pid 3716:tid 140701491482688] AH00094: Command line: '/usr/sbin/apache2'

我发现了invalid optionthingy的问题,这是我在Windows编程上上传用于我的mintty的.bash_profile的结果,我猜不是所有的bash命令都是相同的去图...... 在此处输入图像描述

我希望有一个像这里看到的那样的系统/命令提示 https://youtu.be/7QF0toTZLbw?t=164

注意:不仅是 URL,还有引用的文件。接受的答案即使在 HTML 中引用的图像文件名也有效,<img src="sensitive.jpg"/>而实际文件名是大小写的,所以SenSitive.JpG它真的有效谢谢 APACHE !

在此处输入图像描述

4

1 回答 1

1

如果您有权访问服务器配置,则实际上没有任何需要.htaccess(除非这有助于分发)。

请尝试以下操作:

<VirtualHost *:80>
    # Assuming you want to access the domain apex as well?
    ServerName example.com
    ServerAlias www.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    <Directory /var/www/html>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted

        # Case-Insensitive
        CheckSpelling on
        CheckCaseOnly on
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

并删除.htaccess文件。

请注意 DocumentRoot(您网站的根目录)是/var/www/html. 您需要在相应的<Directory>容器中授予对这个目录的访问权限。并且通常是.htaccess文件应该位于的目录(如果启用)。

于 2020-03-11T21:52:12.453 回答