2012-09-05 80 views
0

我们的系统管理员家伙刚刚离开了一个我正在开发的项目,并且我一直在努力配置我们的生产服务器以匹配TEST(其中一切正常)。在服务器配置方面,我并不是非常了解,而且我已经陷入了很多死路,所以我非常感谢可以提供的帮助。Apache2配置404错误

通过将TEST/var/www复制到PROD,我将代码从测试推广到了PROD。因此,PROD中的应用程序现在驻留在PROD/var/www/www中。 我现在可以访问Production(my.production.com/www)上应用程序的登录页面,但我无法访问var/www/www /的子目录中的任何文件。我不断收到404 Not Found错误。

我已经将该站点的配置(名为'realto'的文件)从TEST复制到PROD,并且运行了a2ensite以创建符合链接到启用网站的文件夹,但我仍然在生产中遇到了404错误。

任何人都可以告诉我什么可能是问题,或指向我在正确的方向吗?

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

的httpd.conf:

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> 

站点配置文件:

<VirtualHost *:80> 
    ServerAdmin [email protected] 

    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:

# 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> 
+0

在同一台机器上测试和生产?从你的问题看来,产品是在测试的子目录?这听起来不对。另外,你可以将你的虚拟主机放在pastebin上吗?你可能不会得到很多人愿意从第三方网站下载文件,而不知道它们包含什么...... – bradym

+0

感谢@bradym,我编辑了问题以包含虚拟主机。 TEST和PROD是云中的独立虚拟机; prod不在测试的子目录中。 – idubs11

回答

0

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

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路径。有时可能很难看到重复的单词/字符,因此用较少重复的内容识别拼写错误会更容易。

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

/var/www/example.com/test/htdocs 
/var/www/example.com/www/htdocs 

这样一来,它是立即清除你在哪个环境,它不是那么混乱。

+0

谢谢@bradym。我已经提出了建议的更改,包括取消注释重写条件并重新启动服务器,但现在尝试访问网站上的任何位置时出现错误(以前访问者已重定向到包含在/ var/www中的我们的博客网站/ blog'文件夹,但他们不能再看到这个内容)。任何想法,为什么这可能是? – idubs11

+0

我没有看到关于博客文件夹的上述问题中的任何内容,所以我不知道如何执行重定向。 index.php文件位于您的网站的位置?它在/ var/www或/ var/www/www中?无论index.php文件在哪里,DirectoryRoot都应指向哪里。当我提出上述更改时,我假设您希望网站在example.com/而不是example.com/www上呈现。不知道如果是这样的话。 – bradym