@yume7kira

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

/var/www/html内のファイルにアクセスできない

Q&A

Closed

解決したいこと

同じ記述内容、同じパーミッション、同じ所有者なのに片方はブラウザでForbiddenとなってしまうのはなぜでしょうか?

仮想マシンの/var/www/htmlにまずtest.htmlを作成しました。

<html>
<head>
<title>test</title>
</head>
<body>
<p>test</p>
</body>
</html>

次にtest.htmlコピーをしてhoge.htmlを作成しました

cp test.html hoge.html

パーミッションと所有者も確認して一緒にしました
image.png

ですが、test.htmlはhttp ://IPアドレス/test.htmlできちんと表示されるのに、http ://IPアドレス/hoge.htmlは以下のようにforbittenになってしまいます
image.png

なぜhoge.htmlはホストのブラウザで表示できないのでしょうか?どなたか教えてください。

(また、/etc/httpd/conf/httpd.confの設定は以下です)

<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>

使用環境
ホストOS:windows11
仮想マシン:almalinux(apacheをインストールしています)

その他に試したこと
〇仮想マシンのreboot
〇ブラウザのキャッシュのクリア

よろしくお願いいたします。

0 likes

4Answer

おそらく、hoge.html と test.html のセキュリティコンテキストが異なるのだと思います。
ls に -lZ オプションを指定して二つに違いがないか確認してください。

/var/www/html 以下であれば以下のコマンドで修復できると思います。

$ restorecon –FR /var/www/html
0Like

The issue likely stems from SELinux security context settings. Even if permissions and ownership are identical, SELinux might block access to newly created or copied files. Check SELinux status with sestatus. If it's enabled, fix the context by running:
restorecon -v /var/www/html/hoge.html https://smart-play.app/
This command restores proper SELinux file context for hoge.html, ensuring it can be accessed by Apache.

0Like

This answer has been deleted for violation of our Terms of Service.

Your answer might help someone💌