如何将旧配置文件从 Apache 2.2.22 传输到 Apache 2.4.6

Posted

技术标签:

【中文标题】如何将旧配置文件从 Apache 2.2.22 传输到 Apache 2.4.6【英文标题】:How to transfer old configuration files from Apache 2.2.22 to Apache 2.4.6 【发布时间】:2013-08-18 19:14:46 【问题描述】:

我是 Apache 新手,当我将 apache 从 2.2.22 更新到 2.4.6 时,我发现我放置 mod_rewrite 设置的默认虚拟主机位置已经改变。

对于 apache2.2.22:它位于 /etc/apache2/sites_enabled/default 中。对于 apache 2.4.6,它发生了变化,帮助文档也说:“NameVirtualHost directiveAs”:不再需要,现在已弃用。

我注意到该设置似乎已从 apache.conf 中删除。这是我对 Apache 2.2.22 和 2.4.6 的配置详细信息。

谁能告诉我我的配置需要改变什么?

对于 apache2.2.22:/etc/apache2/sites_enabled/default

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www
    <Directory />
            Options FollowSymLinks
            AllowOverride All
    </Directory>
    <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
            AllowOverride all
            Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
            Order allow,deny
            Allow from all
    </Directory>

    ErrorLog $APACHE_LOG_DIR/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog $APACHE_LOG_DIR/access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride All
    Order deny,allow
    Deny from all
    Allow from 127.0.0.0/255.0.0.0 ::1/128

<Location />
   AuthName "CIO Internal Demo"
   AuthType Basic
   AuthUserFile /etc/apache2/htpasswd.users
   Require valid-user
</Location>

<Location /liveclass_api/liveclass_callback.php>
    Satisfy Any
    Allow from all
</Location>

<Location /sp_service.php>
    Satisfy Any
    Allow from all
</Location>

                                                                                   1,1           Top

对于 apache2.4.6:/etc/apache2/sites_enabled/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.example.com
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www
    # 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: 语法=apache ts=4 sw=4 sts=4 sr noet

Apache 2.4.6 文件 apache.conf 的一部分

# Include list of ports to listen on
Include ports.conf
# Sets the default security model of the Apache2 HTTPD server. It does
# not allow access to the root filesystem outside of /usr/share and /var/www.
# The former is used by web applications packaged in Debian,
# the latter may be used for local directories served by the web server. If
# your system is serving content from a sub-directory in /srv you must allow
# access here, or in any related virtual host.
<Directory />
    Options FollowSymLinks
    AllowOverride None
    Require all denied
</Directory>

<Directory /usr/share>
    AllowOverride None
    Require all granted
</Directory>

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

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

【问题讨论】:

这些与 mod_rewrite 有什么关系?您可以通过以下方式启用 mod_rewrite:a) 加载模块,b) 在您想要规则的上下文中指定 RewriteEngine,c) 如果您想使用 .htaccess,则至少将 AllowOverride 设置为 FileInfo。如果您的操作系统将 Apache 配置放在多个文件中,请弄清楚布局的使用方式。最终,这一切都得到了结合。 感谢您的回复,我想用 php 部署一个网站,我想用 rewrite 重定向 URL 在 apache 2.4 中:Order allow,deny Allow from all 被替换为 Require all granted 参考这个***.com/questions/22293272/… 【参考方案1】:

您所说的文件和目录看起来就像您在 debian linux 上,因为原始 apache 目录/文件布局不同。 有关从 Apache 2.2 迁移到 2.4 的一般指南,请参阅此处Upgrading to 2.4。 此外,您可能需要查看 debian 是否有一些有关更改的目录/文件结构等的信息。

【讨论】:

以上是关于如何将旧配置文件从 Apache 2.2.22 传输到 Apache 2.4.6的主要内容,如果未能解决你的问题,请参考以下文章

DocumentRoot 没有改变,从 Apache2 2.2.22 更新到 2.4.7

useState 更新状态值,但将旧值作为参数传递给函数

西部数码云服务器手记

Apache 说打开文件读取时出错:权限被拒绝

apache_conf [server]将旧域重写为新域

使用 Apache 将旧域上的旧路径重定向到新域上的新路径