ApacheのドキュメントルートをVagrantの共有フォルダにすると403 Forbiddenになる

Vagrant

Vagrantで起動したCentOSにApacheをインストールして、ドキュメントルートをシンボリックリンクでVagrantの共有フォルダに変更すると、ブラウザでアクセスしたときに403 Forbiddenエラーになってしまいました。
SELinuxを無効にすることで解決できました。

 

エラーになるまでの手順

Vagrantfileの設定はホストからのポートを8080にしているだけです。
“vagrant up”コマンドでCentOSを起動します。

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "CentOS"
  config.vm.network "forwarded_port", guest: 80, host: 8080
end

 

SSHでCentOSへ接続し、Apacheをインストールします。

yum install httpd -y
service httpd start
chkconfig httpd on

 

続いてファイアウォールを停止します。

service iptables stop
chkconfig iptables off

 

ドキュメントルートを削除して、Vagrantの共有フォルダのシンボリックリンクを作成します。

rm -rf /var/www/html
ln -fs /vagrant /var/www/html

 

確認用のindex.htmlファイルを作成します。

echo "Hello, world." > /vagrant/index.html

 

ブラウザで確認すると403 Forbiddenエラーになりました。

Forbidden
You don't have permission to access / on this server.
Apache/2.2.3 (CentOS) Server at localhost Port 8080

403 Forbidden

 

SELinuxを無効にする

“/etc/selinux/config”を編集して”disabled”にします。

vi /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#	enforcing - SELinux security policy is enforced.
#	permissive - SELinux prints warnings instead of enforcing.
#	disabled - SELinux is fully disabled.
SELINUX=disabled
# SELINUXTYPE= type of policy in use. Possible values are:
#	targeted - Only targeted network daemons are protected.
#	strict - Full SELinux protection.
SELINUXTYPE=targeted

 

CentOSを再起動すると、エラーが解消されました。

Hello world

 

コメント

タイトルとURLをコピーしました