如何在Ubuntu上设置虚拟主机

时间:2020-06-08 16:16:22

标签: laravel ubuntu-18.04

我正在努力转向使用Ubuntu进行开发。我正在进行一个令人兴奋的Laravel项目,该项目将于本月底上线。我已经克隆了repro,现在尝试设置虚拟主机(我的理解是,您需要此主机才能使站点在本地正常工作)。我已观看以下视频:https://www.youtube.com/watch?v=lkLAJd-Wb80&t=6s。但是我得到的只是一个404页面未找到。希望有人可以帮助您。

<VirtualHost *:80>
    <Directory /var/www/html/myapp/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Require all granted
    </Directory>

    ServerName myapp.test

    ServerAdmin info@myapp
    DocumentRoot /var/www/html/myapp/public


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

</VirtualHost>

我还将myapp添加到了主机文件中。

2 个答案:

答案 0 :(得分:0)

public中定义路径时错过了<Directory>目录。应该是这样的:

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin info@myapp
        ServerName myapp.test
        ServerAlias myapp.test
        DocumentRoot /var/www/html/myapp/public

        <Directory /var/www/html/myapp/public>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride all
                Order allow,deny
                Allow from all
                Require all granted
        </Directory>

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

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

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

希望这对您有所帮助。

答案 1 :(得分:0)

您能尝试像下面那样监听80端口吗?

Listen 80 
<VirtualHost *:80>
    <Directory /var/www/html/myapp/public>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Require all granted
    </Directory>

    ServerName myapp.test

    ServerAdmin info@myapp
    DocumentRoot /var/www/html/myapp/public


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

</VirtualHost>

我的虚拟主机配置就像下面我使用8080端口一样。

Listen 8080
<VirtualHost *:8080>
    ServerAdmin info@gmail.com
    DocumentRoot "D:/appinstall/htdocs/www/app-test-server/public"
    ServerName localhost
    ErrorLog "logs/app-test-server.log"
    CustomLog "logs/app-test-server.log" common
</VirtualHost>
相关问题