[英]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/ ".我在 Xampp 中有一个 Laravel 安装,我用 url “ http://laravel.test ” 配置了一个虚拟主机,所以我不必写“ 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.问题是,现在每当我在浏览器中写入 url“http:laravel.test”时,它会将我带到 htdocs 文件夹的根目录,当我写入“localhost”时,它会将我带到我的 laravel 项目文件夹。
How can i fix it?我该如何解决? the idea is that when write laravel.test it takes me to my project in laravel5-upaetest/public.
这个想法是,当写 laravel.test 时,它会将我带到我在 laravel5-upaetest/public 中的项目。
This is my httpd-vhosts.conf file:这是我的 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>
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:解释你的问题 - 你会希望在你的
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>
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.其他要检查的事情是重新启动 apache。任何配置更改(*.conf,如 vhosts 文件)都需要重新启动服务器才能加载它们。
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).您还可以添加
AccessLog
和ErrorLog
指令以查看发生了什么(有关示例,请参阅注释掉的##
行,检查日志文件中的任何消息)。
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
您可能需要将
127.0.0.1 laravel.test
添加到您的hosts
文件中,对于 Windows 可以位于例如C:\Windows\System32\drivers\etc
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.