【问题标题】:Problems with virtualhost and alias Laravel 5.4虚拟主机和别名 Laravel 5.4 的问题
【发布时间】:2017-09-28 13:56:46
【问题描述】:

我正在尝试使用带有别名的虚拟主机来部署 Laravel 应用程序。 在 ubuntu 16.04 中使用 apache2。

我的 000.conf 文件是:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    <Directory /var/www/html/>
        Options -Indexes
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <IfModule mod_dir.c>
        DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
    </IfModule>

</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/public

    Alias /expediente "/var/www/public/"

    <Directory /var/www/public/>
        Options -Indexes
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <IfModule mod_dir.c>
        DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
    </IfModule>

</VirtualHost>

第一个工作正常,但第二个不行。

我做错了什么?

==============

编辑

好的,所以我在站点中创建了两个可用的 conf 文件,并将它们符号链接到启用站点。

advanced.conf

<VirtualHost *:80>
    ServerAdmin admin@localhost
    ServerName ip-address:80/advanced
    ServerAlias /advanced
    DocumentRoot /var/www/html/advanced
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

expediente.conf

<VirtualHost *:80>
    ServerAdmin admin@localhost
    ServerName ip-address:80/expediente
    ServerAlias /expediente
    DocumentRoot /var/www/html/public
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

重新加载并重新启动 apache2。

如果我尝试导航到 ip-address/ 我会得到第一页,即高级页面, 如果我尝试导航到 ip-address/advanced 404 not found 如果我尝试导航到 ip-address/expediente 404 not found

我做错了什么?

【问题讨论】:

    标签: php laravel ubuntu apache2 virtualhost


    【解决方案1】:

    它的好习惯是为您的别名创建不同的主机文件。您可以使用此命令通过此命令为您的第二个别名复制默认配置

    sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example.com.conf

    并在您喜欢的任何编辑器中打开它并放置此内容

    <VirtualHost *:80>
        ServerAdmin admin@example.com
        ServerName example.com
        ServerAlias www.example.com
        DocumentRoot /var/www/public
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>
    

    保存并关闭文件,然后运行此命令 sudo a2ensite example.com.conf 并重新启动你的 apache

    【讨论】:

    • 好的,所以我创建了两个 conf 文件,一个用于已经运行的应用程序,另一个用于托管我的 Laravel 应用程序。我将它们命名为 advanced.conf 和 expediente.conf。我也为每个人做了 a2ensite 的事情。每个都有一个 ServerName ipaddress:80/advanced 和 ipaddress:80/expediente,如果我只使用 ipadress:80/ 访问服务器,则它们分别是 DocumentRoot 和 ServerAlias(/advanced 和 /expediente)。如果我尝试访问 ipadress:80/expediente 或 ipadress:80/advanced 它会抛出 404 not found ... 它会是什么?我错过了什么吗?
    • 使用advancedexpediente作为ServerAlias,不要放/
    • 并在浏览器中仅使用别名(您不必使用您的 IP 地址)。如果显示This site can’t be reached,只需编辑/etc/host文件并在文件末尾添加127.0.0.1 yourAlias
    【解决方案2】:

    Si tus proyecto esta de la forma http://localhost/AppName, entonces debes colocar en el httpd.conf

        <VirtualHost site1.local:80>
             ServerAdmin webmaster@example.com
             DocumentRoot /path/to/htdocs/site1
             ServerName www.site1.local
             ServerAlias site1.com 
         </VirtualHost>
    

    你的第二个。

    <VirtualHost site2.local:80>
         ServerAdmin webmaster@example.com
         DocumentRoot /path/to/htdocs/site2
         ServerName www.site2.local
         ServerAlias site2.com
    </VirtualHost>
    

    【讨论】:

    • Y si lo quiero hacer solo con IP?, así como lo muestro en la edición que hice de la pregunta。 No quiero que tenga dominio ya que serán temporales。
    【解决方案3】:

    您将需要在虚拟主机配置中使用 ServerName,如果没有它,它可能总是默认为第一个。例如

    服务器名称 mydomain.net

    【讨论】:

      猜你喜欢
      • 2011-11-04
      • 2012-10-29
      • 2011-04-24
      • 1970-01-01
      • 2012-02-27
      • 2011-06-30
      • 2015-10-06
      • 2011-05-20
      • 2012-11-16
      相关资源
      最近更新 更多