我有点卡住了,我确信这是一个微不足道的问题,但似乎就是找不到正确的解决方案。
我有一个本地开发服务器运行apache2 w/mod_ssl & mod_rewrite。我创建了一个自签名证书,并为*:443添加了相应的虚拟主机指令。我似乎遇到的问题是,现在我有了SSL端的东西可以正常工作了。当我说正确的时候,我的意思是我可以在不添加index.php的情况下转到我的网站的https index.php (例如https://dev.mysite/),它会很好地拉出url。
但当我访问网站的常规http url时,我必须输入index.php才能看到该网站。(例如http://dev.mysite/index.php)
我尝试向*:80块添加一个DirectoryIndex指令,但似乎仍然不起作用。
下面是虚拟主机文件的内容,如果有帮助的话;
ServerName dev.mysite
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/vhosts/bsah_dev/mysite
<Directory />
DirectoryIndex index.php
Options Indexes FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/vhosts/bsah_dev/mysite/>
DirectoryIndex index.html index.htm index.php
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</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>
<VirtualHost *:443>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/vhosts/bsah_dev/mysite
SSLEngine On
<Directory /var/www/vhosts/bsah_dev/mysite>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !^on$ [NC]
RewriteRule . https://%{HTTP_HOST}%{REQUEST_URI} [L]
</IfModule>
</Directory>
SSLOptions +StrictRequire
SSLCertificateFile /etc/apache2/ssl.crt/server.crt
SSLCertificateKeyFile /etc/apache2/ssl.key/server.key
</VirtualHost>发布于 2011-06-21 03:39:24
以下是对您的配置的一些注释,它们可能有助于您解决此问题:
<Directory />
DirectoryIndex index.php
Options Indexes FollowSymLinks
AllowOverride None
</Directory>这很不寻常:通常,您不会授予对根目录(机器的根目录,而不是文档根目录)的任何内容的访问权限。请参阅Directory documentation,其中建议使用以下内容:
<Directory />
Order Deny,Allow
Deny from All
</Directory> 这应该会在您的配置中按预期工作:
<Directory /var/www/vhosts/bsah_dev/mysite/>
DirectoryIndex index.html index.htm index.php
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>(也就是说,只有在没有找到index.html或index.htm的情况下,才会使用index.php。)
DirectoryIndex documentation说它可以放在“服务器配置,虚拟主机,目录,.htaccess”中(参见“上下文”)。它也可以在Directory指令中工作(这样的值将覆盖您在VirtualHost或服务器级别找到的值)。
HTTPS部分中的这条规则没有意义:
<Directory /var/www/vhosts/bsah_dev/mysite>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !^on$ [NC]
RewriteRule . https://%{HTTP_HOST}%{REQUEST_URI} [L]
</IfModule>
</Directory>您正在使用重写规则来重定向到等效的https:// URL。但是,此规则位于启用SSL的部分,因此您将从https://重定向到https://,而不是从http://重定向。
https://stackoverflow.com/questions/6414969
复制相似问题