升級apache後可以看到我的託管文件

升級apache後可以看到我的託管文件

我無法透過 Web 瀏覽器存取本機 PHP 檔案。幸運的是 phpmyadmin 繼續正常工作。

當我在 Firefox 中輸入我的伺服器 IP 時,我得到:

Index of /
[ICO]   Name    Last modified   Size    Description
Apache/2.4.7 (Ubuntu) Server at localhost Port 80

好像 /var/www 是空的,但事實並非如此。我猜想 Apache 現在有一些其他資料夾(或根本沒有)定義為根目錄位置,但我不知道如何修復它。

答案1

您的 html 或 php 檔案必須移動到新的根目錄:

/var/www/html/

答案2

新的 Apache 預設伺服器位置是 /var/www/html。您可以將所有檔案移至新目錄,也可以在終端機(以 root 身分)上執行下列操作:

    # cd /etc/apache2/sites-available
    # nano site1

現在,在奈米貼上以下內容:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName site1

    DocumentRoot /var/www/
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
            Order allow,deny
            Allow from all
    </Directory>

    ErrorLog /var/log/apache2/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog /var/log/apache2/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>
</VirtualHost>

儲存檔案並執行這些命令(再次以 root 身分執行):

    # a2ensite site
    # nano /etc/hosts

現在將其添加到第一行:127.0.0.1 localhost site1

儲存檔案並使用以下命令重新載入 Apache(再次以 root 身分):

    # /etc/init.d/apache2 reload

您應該會收到一則訊息,告訴您 site1 已啟用。現在您可以安全地刪除 /var/www/html 這樣您的伺服器上就沒有空目錄了:

    # rm /var/www/html/

希望有幫助,問候。

答案3

如果您在可用網站中定義了虛擬主機,並且可能託管在 /var/www/html 之外的不同目錄中,那麼您可能已經偶然發現了新的設定檔命名約定。

確保您的虛擬主機設定檔以 .conf 結尾。

完整解釋在這裡: https://askubuntu.com/a/525120/1183

答案4

複製 .html 下的所有 html 檔案/var/www/html。現在打開終端並使用 更改權限sudo chmod -R 777 /var/www,現在在 Firefox 中運行時不會出現此類錯誤。

相關內容