目的
初めまして。プログラミング初心者の者です。
現在、プログラミングを勉強中で、先達のすすめもあり、Vagrantを利用して仮想環境を構築、
仮想環境内に設置したファイルをスマホから閲覧する事を一旦の目標として進めています。
手順としては、
vagrant init centos/7
↓
vagrant up & sshログイン(ログイン後、スーパーユーザーに)
↓
webサーバー(Apache)をインストール、ファイアーウォールを停止、ファイアーウォール自動設定をoffに
↓
httpd.confを修正
EnableMMAP off EnableSendfile off
↓
systemctl enable httpd を適用、Apacheを起動
(ここでsystemctl status httpd(正常に動作), systemctl status firewalld(停止)を確認)
↓
一旦ゲストマシンからログアウト、vagrant halt
↓
Vagrantfileを修正(共有ディレクトリの設定と同じLAN内のデバイスからブラウザでアクセスできるように設定)
↓
vagrant up, sshログインし、 ip a でアドレス確認
↓
共有ディレクトリにindex.htmlを入れる
ここまで行い、確認したIPアドレスに接続したところでトラブルが発生しました。
発生している問題・エラーメッセージ
Error 403 にはならないものの、表示される画面がPC、スマホなどの各デバイス共にApacheのテストページ("Testing 123.."と書いてあるページです)が表示され、index.htmlが表示されませんでした。
きちんとディレクトリ共有がなされていないのではと思い、vagrant ssh → ls /var/www/html(今回共有ディレクトリに設定したディレクトリ=ルートです)を確認した所、ファイルはきちんと存在している。
ホスト側・ゲスト側でで任意のファイルを追加、削除した所、きちんと反映されていることから、ディレクトリ共有自体に問題は無さそうに思いました。
ファイルのアクセスなどが禁止されている訳では無いので、現状SELinuxの線も無いと思っています。
※180414 追記
見事にSELinuxが原因でした。回答を参考に、SELinuxを一旦'Permissive'にして仮想マシンを再起動した結果、表示されるようになりました。
どのようにすれば、ゲストマシンのルートにあるファイルにアクセスできるか、もしくはアクセスできる可能性があるかご教授いただければ幸いです。
参考情報
【ホスト、ゲストマシン情報】
ホスト: macOS High Sierra (10.13.2)
ゲスト: Cent OS7 (Red Hat)
【ホスト側のディレクトリ構成】
┬ dist ─ index.html
├ Vagrantfile
└ .vagrant
【仮想環境構築ツール】
- Vagrant v2.0.3
- virtualbox v5.2.8
【Vagrant Plugin】
- sahara (0.0.17)(今回使ってません)
- vagrant-vbguest (0.15.1)
【Vagrantfile(コメントアウト部は省略)】
Vagrantfile
1Vagrant.configure("2") do |config| 2 3 config.vm.box = "centos/7" 4 5 config.vm.network "private_network", ip: "192.168.33.10" 6 7 config.vm.network "public_network" 8 9 config.vm.synced_folder "./dist", "/var/www/html", type: "virtualbox", id: "vagrant-root", owner: "apache", group: "apache", mount_options:['dmode=777','fmode=777'] 10 11end
※180413追記: 文字数の関係上、コメントアウト部を一部省略しています
【/etc/httpd/conf/httpd.conf】
# This is the main Apache HTTP server configuration file. It contains the #〜省略〜 # ServerRoot "/etc/httpd" # Listen: Allows you to bind Apache to specific IP addresses and/or #〜省略〜 # #Listen 12.34.56.78:80 Listen 80 # Dynamic Shared Object (DSO) Support #〜省略〜 # Include conf.modules.d/*.conf # If you wish httpd to run as a different user or group, you must run #〜省略〜 # User apache Group apache # 'Main' server configuration #〜省略〜 ServerAdmin root@localhost # ServerName gives the name and port that the server uses to identify itself. #〜省略〜 #ServerName www.example.com:80 # Deny access to the entirety of your server's filesystem. You must #〜省略〜 # <Directory /> AllowOverride none Require all denied </Directory> # Note that from this point forward you must specifically allow #〜省略〜 DocumentRoot "/var/www/html" # Relax access to content within /var/www. # <Directory "/var/www"> AllowOverride None # Allow open access: Require all granted </Directory> # Further relax access to the default document root: <Directory "/var/www/html"> #〜省略〜 Options Indexes FollowSymLinks #〜省略〜 AllowOverride None #〜省略〜 Require all granted </Directory> <IfModule dir_module> DirectoryIndex index.html </IfModule> <Files ".ht*"> Require all denied </Files> ErrorLog "logs/error_log" LogLevel warn <IfModule log_config_module> #〜省略〜 LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined LogFormat "%h %l %u %t \"%r\" %>s %b" common <IfModule logio_module> # You need to enable mod_logio.c to use %I and %O LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio </IfModule> #〜省略〜 #CustomLog "logs/access_log" common CustomLog "logs/access_log" combined </IfModule> <IfModule alias_module> ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" </IfModule> <Directory "/var/www/cgi-bin"> AllowOverride None Options None Require all granted </Directory> <IfModule mime_module> TypesConfig /etc/mime.types #AddType application/x-gzip .tgz #AddEncoding x-compress .Z #AddEncoding x-gzip .gz .tgz AddType application/x-compress .Z AddType application/x-gzip .gz .tgz #AddHandler cgi-script .cgi # For type maps (negotiated resources): #AddHandler type-map var #〜省略〜 AddType text/html .shtml AddOutputFilter INCLUDES .shtml </IfModule> #〜省略〜 AddDefaultCharset UTF-8 <IfModule mime_magic_module> #〜省略〜 MIMEMagicFile conf/magic </IfModule> # Some examples: #ErrorDocument 500 "The server made a boo boo." #ErrorDocument 404 /missing.html #ErrorDocument 404 "/cgi-bin/missing_handler.pl" #ErrorDocument 402 http://www.example.com/subscription_info.html # EnableMMAP and EnableSendfile: On systems that support it, #〜省略〜 EnableMMAP off EnableSendfile off IncludeOptional conf.d/*.conf
試したこと
- 共有ディレクトリにファイルの追加、ゲストマシンから操作、確認 → 問題なく同期
- 仮想マシンにssh接続後、apacheユーザーをvboxsfグループに追加 → 以前変わらず
【操作の詳細(ssh接続後)】
[vagrant@localhost ~]$ sudo su - Last login: Thu Apr 12 16:47:04 UTC 2018 on pts/0 [root@localhost ~]# gpasswd -a apache vboxsf Adding user apache to group vboxsf [root@localhost ~]# groups apache apache : apache vboxsf [root@localhost ~]# getent group vboxsf vboxsf:x:995:apache [root@localhost ~]# systemctl restart httpd
何卒よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー