【问题标题】:Set a default Virtual Host in Apache using Debian 10使用 Debian 10 在 Apache 中设置默认虚拟主机
【发布时间】:2021-12-02 02:51:32
【问题描述】:

我有一个小问题。

我有一个配置了 Apache 的 VPS,我有 2 个 VH,一个是 mydomain.com,另一个是 subdomain.mydomain.com

问题是每当我在浏览器中输入 VPS IP 时,它都会转到子域。有没有办法将其默认为主域?

我创建了一个名为 sites-enabled 的文件夹,其中包含两个配置文件,它们看起来像这样。

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>

如何将第一个设置为默认值?

【问题讨论】:

    标签: apache debian virtualhost


    【解决方案1】:

    将以下代码放在 000-default.conf 文件中

    <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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-22
      • 1970-01-01
      • 2017-10-12
      • 2016-04-29
      • 1970-01-01
      • 2018-03-23
      • 1970-01-01
      相关资源
      最近更新 更多