Apache는 도메인 대신 하위 도메인을 제공합니다.

Apache는 도메인 대신 하위 도메인을 제공합니다.

내 서버에는 두 개의 사이트( nextcloud.example.com(Nextcloud 인스턴스) 및 example.com(Grav 인스턴스))가 실행 중이었습니다. 서버에 Postfix 구성을 추가했고 이제 메일도 보낼 수 있습니다. 그런데 인증서에 문제가 있어서 다시 만들었어요...

그만큼주요 문제이제 열려고 할 때 항상 로그인 페이지를 렌더링하는 example.com호출이 발생 하지만 Grav 메인 페이지가 필요합니다. 또한 내가 전화할 때 로 해결됩니다 .example.com/index.php/loginnextcloud.example.comexample.com/adminexample.com/index.php/login

저는 이 주제에 대해 꽤 처음 접했기 때문에 이것이 관련 데이터가 되기를 바랍니다.

$ apachectl configtest
Syntax OK

여기에 conf 파일을 삽입했지만 StackExchange가 내 텍스트 영역을 스팸으로 표시했습니다. 그래서 나는 그것들을 제거했습니다.. 더 많은 정보를 제공하게 되어 기쁘지만, 허락되지 않았습니다...

편집하다:

apache2ctl -S
VirtualHost configuration:
127.0.1.1:443          example.com (/etc/apache2/sites-enabled/example.com-le-ssl.conf:2)
127.0.1.1:80           example.com (/etc/apache2/sites-enabled/example.com.conf:1)
5.252.225.176:443      nextcloud.example.com (/etc/apache2/sites-enabled/nextcloud.example.com-le-ssl.conf:2)
5.252.225.176:80       nextcloud.example.com (/etc/apache2/sites-enabled/nextcloud.example.com.conf:1)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex rewrite-map: using_defaults
Mutex ssl-stapling-refresh: using_defaults
Mutex ssl-stapling: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/var/run/apache2/" mechanism=default 
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33 not_used
Group: name="www-data" id=33 not_used
<VirtualHost nextcloud.example.com:443>
  DocumentRoot /var/www/nextcloud.example.com/htdocs/
  ServerName  nextcloud.example.com

  <Directory /var/www/nextcloud.example.com/htdocs/>
    Require all granted
    AllowOverride All
    Options FollowSymLinks MultiViews

    <IfModule mod_dav.c>
      Dav off
    </IfModule>
  </Directory>
RewriteEngine off
# Some rewrite rules in this file were disabled on your HTTPS site,
# because they have the potential to create redirection loops.

#RewriteCond %{SERVER_NAME} =nextcloud.example.com
#RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
<IfModule mod_ssl.c>
<VirtualHost example.com:443>
  DocumentRoot /var/www/example.com/htdocs/
  ServerName  example.com

  <Directory /var/www/example.com/htdocs/>
    Require all granted
    AllowOverride All
    Options FollowSymLinks MultiViews

    <IfModule mod_dav.c>
      Dav off
    </IfModule>
  </Directory>
RewriteEngine on
# Some rewrite rules in this file were disabled on your HTTPS site,
# because they have the potential to create redirection loops.

#RewriteCond %{SERVER_NAME} =example.com
#RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

답변1

VirtualHost 지시문의 호스트 이름을 *. 즉, 대신

<VirtualHost nextcloud.example.com:443>
  ServerName  nextcloud.example.com
  ...
</VirtualHost>
<Virtualhost example.com:443>
  ServerName  example.com
  ...
</VirtualHost>

노력하다

<VirtualHost *:443>
  ServerName  nextcloud.example.com
  ...
</VirtualHost>
<Virtualhost *:443>
  ServerName  example.com
  ...
</VirtualHost>

일반적으로 VirtualHost의 인수는 IP 주소이거나 *모든 IP 주소와 일치해야 합니다.

Apache가 연결을 수신하는 IP 주소가 example.com의 DNS 주소와 다른 경우 위의 첫 번째 형식은 실패합니다. 예를 들어 example.com이 프록시 뒤에 있는 경우입니다. 이 경우 Apache는 기본 가상 호스트(귀하의 경우 nextcloud.example.com으로 표시되는 첫 번째 호스트)에서 서비스를 제공하도록 대체됩니다.

보다가상호스트, 그리고이름 기반 가상 호스트.

관련 정보