简体   繁体   English

Apache始终提供DocumentRoot index.php

[英]Apache always serving DocumentRoot index.php

This might be a newbie question but... I configured a SSL site in Apache as follows: 这可能是一个新手问题,但是...我在Apache中配置了SSL站点,如下所示:

NameVirtualHost *:443

<VirtualHost *:443>
    ServerName dev.wonnova.com
    DocumentRoot "/var/www/myapp/wwwroot"

    SSLEngine on

    SSLProtocol -all +TLSv1 +SSLv3
    SSLCipherSuite HIGH:MEDIUM:!aNULL:+SHA1:+MD5:+HIGH:+MEDIUM

    SSLCertificateFile /etc/apache2/ssl/mycert.crt
    SSLCertificateKeyFile /etc/apache2/ssl/mycert.key

    <IfModule mime.c>
        AddType application/x-x509-ca-cert      .crt
        AddType application/x-pkcs7-crl         .crl
    </IfModule>

    Alias /mydir/ "/var/www/myapp/mydir"

    <Directory "/var/www/myapp/mydir">
        SSLRequireSSL
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride all
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

The thing is that no matter which URL I request, I always get the contents of /var/www/myapp/wwwroot/index.php (ie index.php in DocumentRoot directory). 问题是,无论我请求哪个URL,我总是得到/var/www/myapp/wwwroot/index.php的内容(即DocumentRoot目录中的index.php)。 It happens for these URLs, as an example: 例如,这些URL发生这种情况:

 - https://mysite/index.php
 - https://mysite/mydir/index.php
 - https://mysite/mydir/style.css
 - https://mysite/mydir/script.js

On the other hand, if I create an index2.php file in DocumentRoot directory, it shows correctly: 另一方面,如果我在DocumentRoot目录中创建一个index2.php文件,它将正确显示:

 - https://mysite/index2.php

I guess there's something that is wrong with my Apache configuration. 我想我的Apache配置有问题。

First of all you can remove the apostrophes from the Alias (I think yours is right though). 首先,您可以从Alias中删除撇号(不过我认为您是对的)。 Change the configuration of your main site: 更改主站点的配置:

Alias /mydir/ "/var/www/myapp/mydir"

    <Directory "/var/www/myapp/mydir">
        SSLRequireSSL
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride all
        Order allow,deny
        Allow from all
    </Directory>

to: 至:

Alias  /mydir /var/www/myapp/mydir
    <Directory /var/www/myapp/mydir>
         SSLRequireSSL
         Allow From all
         Options +Indexes FollowSymLinks Includes ExecCGI
         AllowOverride all 

     </Directory>

Also you need to go to /var/www/myapp/ and edit the .htaccess and change it to: 另外,您还需要转到/ var / www / myapp /并编辑.htaccess并将其更改为:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /mydir/
  RewriteRule ^index\.php$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /mydir/index.php [L]
</IfModule>

I assume you have a DirectoryIndex file (eg index.php) in the /var/www/myapp/mydir to which the alias is pointed. 我假设您在/ var / www / myapp / mydir中有一个DirectoryIndex文件(例如index.php),别名指向该文件。 Let me know if it works 让我知道是否有效

I solved the issue, I had to remove the last slash of the first part of the Alias line. 我解决了这个问题,我不得不删除Alias行第一部分的最后一个斜杠。

This was wrong: 这是错误的:

Alias /mydir/ "/var/www/myapp/mydir"

This is right: 这是对的:

Alias /mydir "/var/www/myapp/mydir"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM