(Apache)访问子域时禁止403

时间:2018-10-22 12:41:47

标签: apache http xampp subdomain httpd.conf

我想在Windows / XAMPP的Apache 2.2服务器上设置子域“商店”,如果我输入“ shop.localhost”作为URL,但是它将重定向到“ index.html”,但是一旦尝试通过我的主机进行连接域“ sv443.net”,它将重定向到我的文档根目录(“ /index.html”而不是“ /shop/index.html”)。连接到“ sv443.net/shop/”虽然可以正常工作,甚至可以重定向到“ index.html”。


我正在使用Cloudflare处理DNS内容并添加了这些记录(我切断了IP地址部分):

enter image description here




这是我的httpd-vhosts.conf:

NameVirtualHost localhost:80

<VirtualHost localhost:80>
   ServerName localhost
   ServerAdmin sven.fehler@web.de

   DocumentRoot "c:/users/sv443/desktop/mamp htdocs"

   <Directory "c:/users/sv443/desktop/mamp htdocs">
     Options Indexes MultiViews FollowSymLinks
     AllowOverride None

     Order allow,deny
     Allow from all
     Require all granted

   </Directory>
</VirtualHost>

<VirtualHost shop.localhost:80>
   ServerName shop.localhost
   ServerAdmin sven.fehler@web.de

   DocumentRoot "c:/users/sv443/desktop/mamp htdocs/shop"

   <Directory "c:/users/sv443/desktop/mamp htdocs/shop">
     Options Indexes MultiViews FollowSymLinks
     AllowOverride None

     Order allow,deny
     Allow from all

     Require all granted
   </Directory>
</VirtualHost>




这是我的东道主。日期:

(only comments)

2.205.169.73 sv443.net

# localhost name resolution is handled within DNS itself.
#   127.0.0.1       localhost
#   ::1             localhost


127.0.0.1   localhost   shop.localhost




我还将此.htaccess文件添加到shop目录中,如果遇到403或404,则重定向到index.html-删除此文件不能解决我的问题:

ErrorDocument 403 /shop/index.html
ErrorDocument 404 /shop/index.html




如果有人尝试连接,我会在Apache error.log中得到以下错误消息:

AH01630: client denied by server configuration: C:/Users/Sv443/Desktop/MAMP htdocs/shop/.html




感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

如果可以通过显式指定“ /index.html”而不是“ /”来获取内容,则在加载mod_dir之后,应在配置中添加DirectoryIndex index.html。这将定义未指定时要查找的默认文件。

对于您的VirtualHost:

<VirtualHost *:80>
    ServerName localhost
    ServerAlias www.example.com
    ServerAlias example.com

    LogLevel debug
    CustomLog "logs/example_access_log" combined
    ErrorLog  "logs/example_error_log"

    [... REST OF CONFIGURATION ...]
</VirtualHost>

<VirtualHost *:80>
    ServerName shop.localhost
    ServerAlias shop.example.com

    LogLevel debug
    CustomLog "logs/shop_access_log" combined
    ErrorLog  "logs/shop_error_log"

    [... REST OF CONFIGURATION ...]
</VirtualHost>

Apache根据请求中的域来决定对请求使用哪个VirtualHost。如果找不到匹配项,它将使用文件中的第一个(此处为localhost)。因此,除非您通过ServerAlias ...在VirtualHost中为其指定“ shop”子域,否则您将不指向它。