skip to Main Content

I know in Apache, there are virtual hosts. When a request is given, it goes and search between these virtual hosts to see if there are server name like request. It takes its option back like document root and others I have this file in /etc/httpd/sites-enabled:

<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/example.com/html
ErrorLog /var/www/example.com/log/error.log
CustomLog /var/www/example.com/log/requests.log combined
</VirtualHost>

I defined all directories as well like /var/www/example.com/html and after all that, I have a file named /etc/httpd/conf at its last line I added this code:

Include sites-enabled/*.conf

After that when I restart httpd it performs complete with no errors, but it doesn’t work and it goes to its default root. Where is the problem?

2

Answers


  1. Chosen as BEST ANSWER

    i solve it just with replacing star with my local ip in linux in virtualhost tag

    <VirtualHost ip:80>
    

    after too many examination it works finally.there was no problem in other places.


  2. Once you create a virtual host configuration file, in your example, /etc/apache2/sites-available/example.com.conf

    You need to use the command as super user

    a2ensite example.com
    

    And then restart Apache:

    systemctl reload apache2
    

    You can tell what virtual hosts are up and running by the command:

    apache2ctl -S
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search