首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Apache2配置404错误

Apache2配置404错误
EN

Stack Overflow用户
提问于 2012-09-05 17:53:16
回答 1查看 1.6K关注 0票数 0

我们的系统管理员刚刚离开了我正在工作的一个项目,我一直在忙于配置我们的生产服务器以匹配测试(在那里一切都可以工作)。当涉及到服务器配置时,我不是很了解,而且我已经陷入了许多死胡同,所以我非常感谢任何可以提供的帮助。

通过将TEST/var/www复制到PROD,我已经将代码从TEST升级到PROD。因此,PROD中的应用程序现在驻留在PROD/var/www/www中。我现在可以访问生产环境中应用程序的登录页面(my.production.com/www),但不能访问var/www/www/子目录中的任何文件。我一直收到404 Not Found错误。

我已经将站点的配置(名为‘realto’的文件)从测试复制到了PROD,并运行了a2ensite来创建指向启用站点的文件夹的符号链接,但我在生产环境中仍然收到了404错误。

有没有人能给我提个建议,或者给我指出正确的方向?

编辑:我已经在下面包含了httpd.conf、ports.conf和站点配置文件的文本。

httpd.conf:

代码语言:javascript
复制
ServerName    my.server.com
ServerSignature Off
ServerTokens Prod
<Directory />
  Order Deny,Allow
  Deny from all
  Options None
  AllowOverride None
</Directory>
<DirectoryMatch /var/www/*>
  Order Allow,Deny
  Allow from all
  AllowOverride All
  Options None
</DirectoryMatch>
<DirectoryMatch phpmyadmin>
  Order Allow,Deny
  Allow from all
  Options None
</DirectoryMatch>

站点配置文件:

代码语言:javascript
复制
    <VirtualHost *:80>
    ServerAdmin xxx@xxxxxxxx.xxx

    DocumentRoot /var/www/www
    <Directory />
        #Options FollowSymLinks
        #AllowOverride None
                Order Deny,Allow
                Deny from All
    </Directory>
    <Directory /var/www/>
                #RewriteEngine On
                #RewriteBase /
                #RewriteCond %{REQUEST_FILENAME} -s [OR]
                #RewriteCond %{REQUEST_FILENAME} -l [OR]
                #RewriteCond %{REQUEST_FILENAME} -d
                #RewriteRule ^.*$ - [NC,L]
                #RewriteRule ^.*$ index.php [NC,L]
                Order Allow,Deny
                Allow from all

        Options -Indexes FollowSymLinks MultiViews
        AllowOverride All
    </Directory>
    <Directory /var/www/www/application/configs/>
          <Files ~ "\.ini$">
                Deny from All
          </Files>
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        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 None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

ports.conf:

代码语言:javascript
复制
# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default
# This is also true if you have upgraded from before 2.2.9-3 (i.e. from
# Debian etch). See /usr/share/doc/apache2.2-common/NEWS.Debian.gz and
# README.Debian.gz

NameVirtualHost *:80
Listen 80

<IfModule mod_ssl.c>
    # If you add NameVirtualHost *:443 here, you will also have to change
    # the VirtualHost statement in /etc/apache2/sites-available/default-ssl
    # to <VirtualHost *:443>
    # Server Name Indication for SSL named virtual hosts is currently not
    # supported by MSIE on Windows XP.
    Listen 443
</IfModule>

<IfModule mod_gnutls.c>
    Listen 443
</IfModule>
EN

回答 1

Stack Overflow用户

发布于 2012-09-10 05:20:20

要做的第一件事是使DocumentRoot和条目匹配。

代码语言:javascript
复制
DocumentRoot /var/www/www
<Directory /var/www/www>
    #RewriteEngine On
    #RewriteBase /
    #RewriteCond %{REQUEST_FILENAME} -s [OR]
    #RewriteCond %{REQUEST_FILENAME} -l [OR]
    #RewriteCond %{REQUEST_FILENAME} -d
    #RewriteRule ^.*$ - [NC,L]
    #RewriteRule ^.*$ index.php [NC,L]
    Order Allow,Deny
    Allow from all

    Options -Indexes FollowSymLinks MultiViews
    AllowOverride All
</Directory>

有了这个DocumentRoot,访问您的站点将服务于/var/www/www中的内容。这意味着访问http://example.com/www实际上是在/var/www/www/www中查找文件。

既然DocumentRoot和Directory指令匹配,您真的希望注释掉所有的mod_rewrite规则吗?现在,当您请求/var/www/www中实际不存在的任何文件时,您将得到一个404。如果您的应用程序需要将请求路由到index.php,则需要取消对这些行的注释。(我猜它们可能会为了测试而被注释掉,但只是以防万一…)

顺便说一句,将来我会建议一个不那么令人困惑的docroot路径。有时很难看到重复的单词/字符,因此更容易识别重复程度较低的拼写错误。

我喜欢这样设置我的应用程序:

代码语言:javascript
复制
/var/www/example.com/test/htdocs
/var/www/example.com/www/htdocs

这样一来,你所处的环境就会一目了然,而且也不会那么令人困惑。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12278742

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档