Apache default VirtualHost

前端 未结 9 1658
忘掉有多难
忘掉有多难 2020-12-05 17:53

how can I set a default VirtualHost in apache? Preferably, I want the default host not to be the same as the ip address host. Now I have something like this:



        
9条回答
  •  天命终不由人
    2020-12-05 17:53

    I will say what worked for me, the others answers above didn't help to my case at all. I hope it can help someone.

    Actually, I'm using Virtual host configuration (sites-available / sites-enabled) on EC2 Linux AMI with Apache/2.4.39 (Amazon). So, I have 1 ec2 instance to serve many sites (domains).

    Considering that you already have Virtual Host installed and working. In my folder /etc/httpd/sites-available, I have some files with domain names (suffix .conf), for example: domain.com.conf. Create a new file like that.

    sudo nano /etc/httpd/sites-available/domain.com.conf

    
        ServerName www.domain.com
        ServerAlias domain.com
        DocumentRoot /var/www/html/domain
    
    

    For each file.conf in sites-available, I create a symbolic link:

    sudo ln -s /etc/httpd/sites-available/domain.com.conf /etc/httpd/sites-enabled/domain.com.conf

    This is the default configuration, so, if access directly by IP of Server, you will be redirect to DocumentRoot of the first file (.conf) in sites-available folder, sorted by filename.

    To have a default DocumentRoot folder when access by IP, you have to create a file named 0a.conf, then apache will serve this site because this new file will be the first in sites-available folder.

    You must create a symbolic link:

    sudo ln -s /etc/httpd/sites-available/0a.conf /etc/httpd/sites-enabled/0a.conf

    To check serving order, use it:

    sudo apachectl -S

    Now, restart apache, and check out it.

    Be happy =)

提交回复
热议问题