【问题标题】:Apache Virtual Host not getting to the right folderApache 虚拟主机没有进入正确的文件夹
【发布时间】:2018-07-05 03:10:16
【问题描述】:

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

【问题讨论】:

  • 你记得重启 apache 吗?任何配置更改(*.conf 像 vhosts 文件)都需要重新启动服务器才能加载它们。您还可以添加 AccessLogErrorLog 指令以查看发生了什么(请参阅注释掉的 ## 行示例)

标签: php laravel apache


【解决方案1】:
<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>

【讨论】:

  • 欢迎来到 Stack Overflow!不鼓励仅使用代码的答案。请单击编辑并添加一两段来总结您的代码如何解决问题,或者解释您的答案与之前的答案/答案有何不同。谢谢。
  • 请为您的代码的工作原理添加一些说明。仅代码答案对未来的读者没有任何价值。
【解决方案2】:

enter image description here
我想,你已经使用了所有类型的工作。

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

【讨论】:

  • 上述代码适用于您可以访问诸如 Bash 或 Sh 之类的 shell 的系统,并假定安装了诸如 a2ensitenano 之类的程序,并且 APACHE_LOG_DIR 作为环境变量存在。 .. 感觉完全没有回答这个基于 Windows 的问题的意义
【解决方案3】:

这些行

# 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

【讨论】:

    猜你喜欢
    • 2016-04-14
    • 1970-01-01
    • 2016-03-11
    • 1970-01-01
    • 2014-11-13
    • 2020-05-25
    • 2012-08-11
    • 2020-10-18
    • 2014-12-29
    相关资源
    最近更新 更多