简体   繁体   中英

Set a default Virtual Host in Apache using Debian 10

I have a little problem.

I have a VPS configured with Apache, I have 2 VH, one is mydomain.com and other is subdomain.mydomain.com

Problem is that whenever I type the VPS IP in the browser, it goes to the subdomain. Is there a way to default this to the main domain?

I've created a folder called sites-enabled which contains both configuration files, they look something like this.

example.net.conf:

<VirtualHost *:80>
    ServerName example.net
    ServerAlias www.example.net
    DocumentRoot /var/www/example.net
    
    <Directory /var/www/example.net>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
     </Directory>

    <FilesMatch \.php$>
      SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost"
    </FilesMatch>

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

admin.example.net.conf:

<VirtualHost *:80>
     ServerName admin.example.net
     DocumentRoot /var/www/admin.example.net
     DirectoryIndex index.html
     ErrorLog ${APACHE_LOG_DIR}/admin.example.net.log
     CustomLog ${APACHE_LOG_DIR}/admin.example.net.log combined
</VirtualHost>

How can I set the first one to be the default?

place the below code in the 000-default.conf file

<VirtualHost *:80>
    
    DocumentRoot /var/www/example.net
    
    <Directory /var/www/example.net>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
     </Directory>

    <FilesMatch \.php$>
      SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost"
    </FilesMatch>

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

</VirtualHost>

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