Search code examples
apachehttp-redirectvirtualhosthttpd.conf

virtual host Redirects Me To Apache default Page Testing 123


I setup Anything in My Server To Connect To A Domain But I have A Problem Httpd Virtual Host Redirect me To Default Apache Page I don't Know Why I Tried Every Solution On Internet But Nothing works. Here is My File If Anything Else Needed Tell me:

<VirtualHost *:80>
    documentRoot /var/www/buymeacookie.ir/public_html
    ServerName buymeacookie.ir
    ErrorLog /var/www/buymeacookie.ir/error.log
    CustomLog /var/www/buymeacookie.ir/requests.log combined
    #Redirect "/" "https://www.buymeacookie.ir/"
</VirtualHost>

I Also Made /var/www/buymeacookie.ir/

and /var/www/buymeacookie.ir/public_html/

and added a index.html on public_html But When I Open My URL I get Default Page of Apache.

thank you for reading :D

EDIT tree of /var/www is

/var/www
├── buymeacookie.ir
│   ├── access.log
│   ├── error_log
│   ├── error.log
│   ├── public_html
│   │   └── index.html
│   └── requests.log
├── cgi-bin
└── html

Solution

  • this is how I would configure such a site. The requirements I figure out from your question:

    • domain: www.example.com and example.com
    • the files for this domain are in /var/www/example.com/public_html/
    • that domain is setup as a VirtualHost, with separated logs for this domain
    • IMPORTANT: there are no other VirtualHosts for port 80
    • the top directory for Apache will be /opt/apache
    • logs will end up in /opt/apache/logs
    • default content files are in /opt/apache/htdocs
    • /var/www/example.com/public_html/ must be owned by user httpd, group httpd, permissions 750
    • if owned by another user, the permissions should be 755, but this is less secure
    • modules must be added or removed according to your requirements
    • obviously, you must adjust the directories according to your system

    /opt/apache/conf/httpd.conf

    ServerRoot "/opt/apache"
    
    Listen 80
    
    LoadModule authn_file_module modules/mod_authn_file.so
    LoadModule authn_core_module modules/mod_authn_core.so
    LoadModule authz_host_module modules/mod_authz_host.so
    LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
    LoadModule authz_user_module modules/mod_authz_user.so
    LoadModule authz_core_module modules/mod_authz_core.so
    LoadModule access_compat_module modules/mod_access_compat.so
    LoadModule auth_basic_module modules/mod_auth_basic.so
    LoadModule reqtimeout_module modules/mod_reqtimeout.so
    LoadModule filter_module modules/mod_filter.so
    LoadModule mime_module modules/mod_mime.so
    LoadModule log_config_module modules/mod_log_config.so
    LoadModule env_module modules/mod_env.so
    LoadModule headers_module modules/mod_headers.so
    LoadModule setenvif_module modules/mod_setenvif.so
    LoadModule version_module modules/mod_version.so
    LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
    LoadModule unixd_module modules/mod_unixd.so
    LoadModule status_module modules/mod_status.so
    LoadModule autoindex_module modules/mod_autoindex.so
    LoadModule dir_module modules/mod_dir.so
    
    <IfModule unixd_module>
        User httpd
        Group httpd
    </IfModule>
    
    ServerName example.com:80
    
    <Directory />
        AllowOverride none
        Require all denied
    </Directory>
    
    DocumentRoot "/opt/apache/htdocs"
    <Directory "/opt/apache/htdocs">
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>
    
    <IfModule dir_module>
        DirectoryIndex index.html index.php
    </IfModule>
    
    ErrorLog "logs/error_log"
    LogLevel debug
    <IfModule log_config_module>
        LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
        LogFormat "%h %l %u %t \"%r\" %>s %b" common
        <IfModule logio_module>
            LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
        </IfModule>
        CustomLog "logs/access_log" combined
    </IfModule>
    
    <IfModule mime_module>
        TypesConfig conf/mime.types
    
        AddType application/x-compress .Z
        AddType application/x-gzip .gz .tgz
    </IfModule>
    
    Include conf/extra/httpd-mpm.conf
    Include conf/extra/httpd-vhosts.conf
    Include conf/extra/httpd-default.conf
    

    /opt/apache/conf/extra/httpd-vhosts.conf

    <VirtualHost *:80>
    
        ServerName example.com
        ServerAlias www.example.com
    
        ServerAdmin [email protected]
    
        LogLevel debug
        ErrorLog "logs/example.com_error_log"
        CustomLog "logs/example.com_access_log" combined
    
        DocumentRoot "/var/www/example.com/public_html/"
        <Directory "/var/www/example.com/public_html/">
            Options Indexes FollowSymLinks
            AllowOverride None
            Require all granted
        </Directory>
    
        DirectoryIndex index.html
    
    </VirtualHost>
    

    With this setup:

    • if you call http://www.example.com or http://example.com, the files will come from /var/www/example.com/public_html/
    • logs under /opt/apache/logs will indicate the start of the httpd
    • logs /opt/apache/logs/example.com_*_log will show the transactions and/or errors from your tests

    Obviously, this is a starting point, you must adjust for your other requirements.