简体   繁体   中英

Having trouble setting up up an Apache name-based virtual host on my local system

I am unable to configure the virtual host. When I finish configuring to inspect going to the page I showed in the file /etc/apache2/sites-available/gdex.dev.conf , you go to the root folder of the localhost ( 127.0.0.1 )

Here is my config in /etc/apache2/sites-available/gdex.dev.conf

<VirtualHost *:80>

    ServerName gdex.dev
        ServerAlias www.gdex.dev
    ServerRoot /var/www/html/gdex.dev/
    DocumentRoot /var/www/html/gdex.dev/

    <Directory "/var/www/html/gdex.dev">
        Options +Indexes +FollowSymLinks
        Order allow,deny
        Allow from all
        AllowOverride All
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/gdex.dev.log
    CustomLog ${APACHE_LOG_DIR}/gdex.dev.log combined


</VirtualHost>

And here is the content in /etc/hosts :

127.0.0.1 localhost  
127.0.1.1 xubuntu

127.0.0.1 gdex.dev

What am I doing wrong?

In your question you are showing the configuration being set in /etc/apache2/sites-available/gdex.dev.conf but is there a symbolic link set from that to sites-enabled ?

That configuration being in sites-available simply means that config available for use; sites-enabled means the config is now actually enabled and will be loaded by Apache.

You can set the config to be in sites-available using a command like this:

sudo ln -s /etc/apache2/sites-available/gdex.dev.conf /etc/apache2/sites-enabled/gdex.dev.conf

And then reload Apache config via this standard service reload command:

sudo service apache2 reload

After doing that service reload , check your virtual host list running this command:

sudo apachectl -S

The output should then be something like this:

VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80                   is a NameVirtualHost
         port 80 namevhost gdex.dev (/etc/apache2/sites-enabled/gdex.dev.conf:1)

The thing to note is the line that has port 80 namevhost gdex.dev in it. If somehow that doesn't show up, try to force restarting the Apache server like this:

sudo service apache2 restart

And then check the output of sudo apachectl -S again for that port 80 namevhost gdex.dev item.

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