簡體   English   中英

Apache 虛擬主機未進入正確的文件夾

[英]Apache Virtual Host not getting to the right folder

我在 Xampp 中有一個 Laravel 安裝,我用 url “ http://laravel.test ” 配置了一個虛擬主機,所以我不必寫“ http://localhost/laravel5-upaetest/public/ ”。

問題是,現在每當我在瀏覽器中寫入 url“http:laravel.test”時,它會將我帶到 htdocs 文件夾的根目錄,當我寫入“localhost”時,它會將我帶到我的 laravel 項目文件夾。

我該如何解決? 這個想法是,當寫 laravel.test 時,它會將我帶到我在 laravel5-upaetest/public 中的項目。

這是我的 httpd-vhosts.conf 文件:

# Virtual Hosts
#
# Required modules: mod_log_config

# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at 
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
##NameVirtualHost *:80
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ##ServerName or ##ServerAlias in any <VirtualHost> block.
#
##<VirtualHost *:80>
    ##ServerAdmin webmaster@dummy-host.example.com
    ##DocumentRoot "C:/xampp/htdocs/dummy-host.example.com"
    ##ServerName dummy-host.example.com
    ##ServerAlias www.dummy-host.example.com
    ##ErrorLog "logs/dummy-host.example.com-error.log"
    ##CustomLog "logs/dummy-host.example.com-access.log" common
##</VirtualHost>

##<VirtualHost *:80>
    ##ServerAdmin webmaster@dummy-host2.example.com
    ##DocumentRoot "C:/xampp/htdocs/dummy-host2.example.com"
    ##ServerName dummy-host2.example.com
    ##ErrorLog "logs/dummy-host2.example.com-error.log"
    ##CustomLog "logs/dummy-host2.example.com-access.log" common
##</VirtualHost>



<Directory c:/xampp>

    AllowOverride All
    Require all granted
    Allow from all
</Directory>

<VirtualHost *:80>
    DocumentRoot c:/xampp/htdocs/laravel5-upaetest/public
    ServerName laravel.test
</VirtualHost>

在此處輸入圖片說明
我認為,您已經使用了所有類型的工作。

But you have a mistake, i think.
Use code like below...
1. sudo mkdir -p /var/www/example.com
2. sudo chown -R $USER:$USER /var/www/example.com
3. sudo chmod -R 755 /var/www
4. sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example.com.conf
5. sudo nano /etc/apache2/sites-available/example.com.conf
6. <VirtualHost *:80>
    ServerAdmin admin@example.com
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
7. sudo a2ensite example.com.conf
8. sudo a2dissite 000-default.conf
9. sudo systemctl restart apache2
10. sudo nano /etc/hosts
11. 127.0.1.1  www.example.com example.com
<VirtualHost *:80>
     ServerName localhost
     DocumentRoot "C:\xampp\htdocs"
     <Directory "C:\xampp\htdocs">

     </Directory>
 </VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/job/public"
    ServerName job.dev
    <Directory "C:/xampp/htdocs/job/public">
        Options FollowSymLinks
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>

這些線

# The first VirtualHost section is used for all requests that do not # match a ##ServerName

解釋你的問題 - 你會希望在你的httpd-vhosts.conf中有兩個塊,第一個是通用服務器文件路徑:

<Directory c:/xampp>

    AllowOverride All
    Require all granted
    Allow from all
</Directory>

<VirtualHost *:80>
    DocumentRoot c:/xampp/htdocs
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot c:/xampp/htdocs/laravel5-upaetest/public
    ServerName laravel.test
</VirtualHost>


其他要檢查的事情是重新啟動 apache。任何配置更改(*.conf,如 vhosts 文件)都需要重新啟動服務器才能加載它們。

您還可以添加AccessLogErrorLog指令以查看發生了什么(有關示例,請參閱注釋掉的##行,檢查日志文件中的任何消息)。

您可能需要將127.0.0.1 laravel.test添加到您的hosts文件中,對於 Windows 可以位於例如C:\Windows\System32\drivers\etc

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM