简体   繁体   中英

Apache Virtual Host not getting to the right folder

I have a Laravel installation in Xampp and i configured a virtualhost with the url " http://laravel.test " so i don't have to write " http://localhost/laravel5-upaetest/public/ ".

The problem is that now whenever i write the url "http:laravel.test" in my browser it takes me to the root of the htdocs folder and when i write "localhost" it takes me to my laravel project folder.

How can i fix it? the idea is that when write laravel.test it takes me to my project in laravel5-upaetest/public.

This is my httpd-vhosts.conf file:

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

enter image description here
I Think, You already use all types of work.

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>

these lines

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

explain your issue - you'll want to have two blocks in your httpd-vhosts.conf with the first being the generic server files path:

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


other things to check would be to restart apache. any config changes (*.conf like the vhosts file) will require a restart of the server to load them.

you can also add AccessLog and ErrorLog directives to see what's going on (see the commented out ## lines for examples, check the log files for any messages).

you'll probably want to add 127.0.0.1 laravel.test to your hosts file, which for Windows can live in eg C:\Windows\System32\drivers\etc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM