programing tip

아파치 가상 호스트 구성을 디버깅하는 방법?

itbloger 2020. 7. 3. 20:21
반응형

아파치 가상 호스트 구성을 디버깅하는 방법?


다시 한 번 아파치 가상 호스트 구성에 문제가 있습니다. (기본 구성은 특정 구성 대신 사용됩니다).

문제는 실제로 잘못된 구성이 아니라 해결 방법입니다.

누구든지 이런 종류의 문제를 빨리 해결할 수있는 좋은 조언이 있습니까?

더 많은 정보.

기본 conf 파일은 다음과 같습니다.

NameVirtualHost *
<VirtualHost *>
        ServerAdmin webmaster@localhost

        DocumentRoot /var/www/
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog /var/log/apache2/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog /var/log/apache2/access.log combined
        ServerSignature On

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

적용되지 않는 가상 호스트 구성은 다음과 같습니다.

<VirtualHost *:*>

ProxyPreserveHost On
ProxyPass / http://ip.ip.ip.ip:8088/
ProxyPassReverse / http://ip.ip.ip.ip:8088/
ServerName wiki.mydomain.com

</VirtualHost>

구문 검사

구성 파일에서 구문 오류를 확인하려면

# Red Hat-based (Fedora, CentOS) and OSX
httpd -t

# Debian-based (Ubuntu)
apache2ctl -t

# MacOS
apachectl -t

가상 호스트 나열

모든 가상 호스트 및 해당 위치를 나열하려면

# Red Hat-based (Fedora, CentOS) and OSX
httpd -S

# Debian-based (Ubuntu)
apache2ctl -S

# MacOS
apachectl -S

도움이 될 수 있다고 생각되는 명령은 다음과 같습니다.

apachectl -t -D DUMP_VHOSTS

모든 가상 호스트 목록을 얻을 수 있습니다. 어떤 가상 호스트가 기본 호스트인지 알고 구문이 올바른지 확인하십시오 (yojimbo87이 제안한 apachectl configtest와 동일).

You'll also know where each vhost is declared. It can be handy if your config files are a mess. ;)


If you are trying to debug your virtual host configuration, you may find the Apache -S command line switch useful. That is, type the following command:

httpd -S

This command will dump out a description of how Apache parsed the configuration file. Careful examination of the IP addresses and server names may help uncover configuration mistakes. (See the docs for the httpd program for other command line options).


First check out config files for syntax errors with apachectl configtest and then look into apache error logs.


I had a new VirtualHost configuration file that was not showing when using the apachectl -S command. After much head scratching I realised that my file did not have suffix ".conf". Once I renamed the file with that suffix my Vhost started showing and working!


I recently had some issues with a VirtualHost. I used a2ensite to enable a host but before running a restart (which would kill the server on fail) I ran

apache2ctl -S

Which gives you some info about what's going on with your virtual hosts. It's not perfect, but it helps.


I found my own mistake, I did not add log file name: ErrorLog /var/log/apache2
And this path: Directory "/usr/share/doc/" Did not contain website sources.

After I changed these two, all worked. Interestingly, apache did not issue any errors, just did not open my website silently on my Mac OS Sierra.

참고URL : https://stackoverflow.com/questions/5474477/how-to-debug-an-apache-virtual-host-configuration

반응형