简体   繁体   English

启用虚拟主机时,Apache返回403

[英]Apache returns 403 when I enable virtual hosts

I just set up a Cent OS 6 VPS which runs LAMP perfectly until I enabled the virtual hosts. 我只是设置了一个Cent OS 6 VPS,它可以完美地运行LAMP,直到启用虚拟主机为止。 It always returns 403 Forbidden error. 它始终返回403禁止错误。

I updated /etc/httpd/conf/httpd.conf as following settings: 我将/etc/httpd/conf/httpd.conf更新为以下设置:

<Directory />
#    Options Indexes FollowSymLinks MultiViews Includes ExecCGI
    Options FollowSymLinks
    AllowOverride All
#    Order deny,allow
    Order allow,deny
    Allow from all
#    Deny from all
</Directory>

<Directory "/var/www/html">
    Options Indexes FollowSymLinks MultiViews
    #AllowOverride None
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

NameVirtualHost *:80

I have created /etc/httpd/conf.d/vhosts.conf which is loaded by /etc/httpd/conf/httpd.conf. 我创建了/etc/httpd/conf.d/vhosts.conf,该文件由/etc/httpd/conf/httpd.conf加载。 (I replaced my real domain and username by "mydomain") (我用“ mydomain”替换了我的真实域名和用户名)

<VirtualHost *:80>
     ServerAdmin webmaster@mydomain

     DocumentRoot /home/mydomain/htdocs
     <Directory /home/mydomain/htdocs>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
     </Directory>
     ServerName mydomain
     ServerAlias mydomain
     ErrorLog /home/mydomain/logs/error.log
#     CustomLog /home/mydomain/logs/access.log common
</VirtualHost>

I changed the owner and permissions of both /var/www/html and /home/mydomain/htdocs. 我更改了/ var / www / html和/ home / mydomain / htdocs的所有者和权限。

drwxr-xr-x 3 apache apache 4096 Aug 15 14:23 html

drwxr-xr-x 2 apache apache 4096 Aug 18 10:18 htdocs
drwxr-xr-x 2 apache apache 4096 Aug 18 10:37 logs

But now I can't access the virtual host even the root documents (/var/www/html) by IP address. 但是现在我无法通过IP地址访问虚拟主机,甚至无法访问根文档(/ var / www / html)。 If I turn off (remove) the virtual host, then I can access the pages in the /var/www/html. 如果关闭(删除)虚拟主机,则可以访问/ var / www / html中的页面。

Can anyone help me out? 谁能帮我吗?

Thanks a lot. 非常感谢。

If it's 403 Forbidden Then probably it's permission error, So make sure you apply permissions recursively. 如果它是403 Forbidden则可能是权限错误,因此请确保您递归应用权限。 Type this in the Terminal 在终端中输入

sudo chmod 755 -R /home/mydomain/htdocs

Try this in your conf 在你的conf中尝试

<VirtualHost *:80>

    DocumentRoot "/path/to/your/site"

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

I just solved the problem by changing the permission of /home/mydomain/ directory to 755 which was 700. 我只是通过将/ home / mydomain /目录的权限更改为755(即700)解决了该问题。

Thanks for Akar's help. 感谢Akar的帮助。 He did mention the permissions. 他确实提到了权限。

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

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