You are not logged in.

#1 2012-04-12 13:45:48

trusktr
Banned
From: .earth
Registered: 2010-02-18
Posts: 907
Website

[SOLVED] I can't get virtual hosts working. What's wrong?

What I've decided to do is try to set up each domain name in the user folder to whom it belongs (for example: /home/username/somedomain.com/htdocs). I can't get it to work though. I keep getting an error saying that there's no index file (although there is) or that the location isn't readable (although it is). I'm trying to make it so that if the domain name matches with a virtual host section in httpd-vhosts.conf that a specific DocumentRoot will be loaded for that domain, etc. But, if the domain name points to my server but doesn't match, then I want the default location to work. I can't seem to make this work.

This is my http.conf:

ServerRoot "/etc/httpd"

Listen 80

LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_dbm_module modules/mod_authn_dbm.so
LoadModule authn_anon_module modules/mod_authn_anon.so
LoadModule authn_dbd_module modules/mod_authn_dbd.so
LoadModule authn_default_module modules/mod_authn_default.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_dbm_module modules/mod_authz_dbm.so
LoadModule authz_owner_module modules/mod_authz_owner.so
LoadModule authnz_ldap_module modules/mod_authnz_ldap.so
LoadModule authz_default_module modules/mod_authz_default.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule auth_digest_module modules/mod_auth_digest.so
LoadModule file_cache_module modules/mod_file_cache.so
LoadModule cache_module modules/mod_cache.so
LoadModule disk_cache_module modules/mod_disk_cache.so
LoadModule mem_cache_module modules/mod_mem_cache.so
LoadModule dbd_module modules/mod_dbd.so
LoadModule dumpio_module modules/mod_dumpio.so
LoadModule reqtimeout_module modules/mod_reqtimeout.so
LoadModule ext_filter_module modules/mod_ext_filter.so
LoadModule include_module modules/mod_include.so
LoadModule filter_module modules/mod_filter.so
LoadModule substitute_module modules/mod_substitute.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule ldap_module modules/mod_ldap.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule log_forensic_module modules/mod_log_forensic.so
LoadModule logio_module modules/mod_logio.so
LoadModule env_module modules/mod_env.so
LoadModule mime_magic_module modules/mod_mime_magic.so
LoadModule cern_meta_module modules/mod_cern_meta.so
LoadModule expires_module modules/mod_expires.so
LoadModule headers_module modules/mod_headers.so
LoadModule ident_module modules/mod_ident.so
LoadModule usertrack_module modules/mod_usertrack.so
LoadModule unique_id_module modules/mod_unique_id.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule version_module modules/mod_version.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_scgi_module modules/mod_proxy_scgi.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule ssl_module modules/mod_ssl.so
LoadModule mime_module modules/mod_mime.so
LoadModule dav_module modules/mod_dav.so
LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule asis_module modules/mod_asis.so
LoadModule info_module modules/mod_info.so
LoadModule suexec_module modules/mod_suexec.so
LoadModule cgi_module modules/mod_cgi.so
LoadModule cgid_module modules/mod_cgid.so
LoadModule dav_fs_module modules/mod_dav_fs.so
LoadModule vhost_alias_module modules/mod_vhost_alias.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule dir_module modules/mod_dir.so
LoadModule imagemap_module modules/mod_imagemap.so
LoadModule actions_module modules/mod_actions.so
LoadModule speling_module modules/mod_speling.so
LoadModule userdir_module modules/mod_userdir.so
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so

#CUSTOM
LoadModule php5_module modules/libphp5.so

<IfModule !mpm_netware_module>
<IfModule !mpm_winnt_module>
User http
Group http

</IfModule>
</IfModule>

ServerAdmin you@example.com

DocumentRoot "/srv/http/default/htdocs"

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>

<Directory "/srv/http/default/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

<IfModule dir_module>
    DirectoryIndex index.php,index.html
</IfModule>

<FilesMatch "^\.ht">
    Order allow,deny
    Deny from all
    Satisfy All
</FilesMatch>

ErrorLog "/var/log/httpd/error_log"

LogLevel warn

<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>
      # You need to enable mod_logio.c to use %I and %O
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>

    CustomLog "/var/log/httpd/access_log" common

</IfModule>

<IfModule alias_module>
    ScriptAlias /cgi-bin/ "/srv/http/cgi-bin/"

</IfModule>

<IfModule cgid_module>
    #Scriptsock /var/run/httpd/cgisock
</IfModule>

<Directory "/srv/http/cgi-bin">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>

DefaultType text/plain

<IfModule mime_module>
    TypesConfig conf/mime.types

    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz

</IfModule>

# Multi-language error messages
Include conf/extra/httpd-multilang-errordoc.conf

# Fancy directory listings
Include conf/extra/httpd-autoindex.conf

# Language settings
Include conf/extra/httpd-languages.conf

# User home directories
#Include conf/extra/httpd-userdir.conf

# Real-time info on requests and configuration
#Include conf/extra/httpd-info.conf

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

# Local access to the Apache HTTP Server Manual
#Include conf/extra/httpd-manual.conf

# Distributed authoring and versioning (WebDAV)
#Include conf/extra/httpd-dav.conf

# Various default settings
Include conf/extra/httpd-default.conf

#CUSTOM
Include conf/extra/php5_module.conf

<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>

And here's my httpd-vhosts.conf:

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName   45.117.5.40
    ServerAdmin  default@example.com
    DocumentRoot "/srv/http/default/htdocs"
    ErrorLog     "/srv/http/default/log/error_log"
    CustomLog    "/srv/http/default/log/access_log" common
</VirtualHost>

<VirtualHost *:80>
    ServerName   somedomain.com
    ServerName   www.somedomain.com
    ServerAdmin  blah@example.com
    DocumentRoot "/home/normaluser/somedomain.com/htdocs"
    ErrorLog     "/home/normaluser/somedomain.com/log/error_log"
    CustomLog    "/home/normaluser/somedomain.com/log/access_log" common
</VirtualHost>

So, for example, I want it to be so that if I visit http://45.117.5.40 that it'll show the stuff ftom /srv/http/default/htdocs but if the domain name matches somedomain.com then I want the server to show the content from /home/normaluser/somedomain.com/htdocs.

What currently happens is that if I visit http://45.117.5.40 or somedomain.com, they both show the same content from /srv/http/default/htdocs.

If I comment out the first VirtualHost section, then everything stops working and I see the default "Access forbidden!" message.

What am I doing wrong?

Last edited by trusktr (2012-04-13 06:15:41)


joe@trusktr.io - joe at true skater dot io.

Offline

#2 2012-04-13 06:13:57

trusktr
Banned
From: .earth
Registered: 2010-02-18
Posts: 907
Website

Re: [SOLVED] I can't get virtual hosts working. What's wrong?

I fixed it. In case any newbs come across this, I had to add a new <Directory> section for the DocumentRoot of the virtual host. Simply adding the VirtualHost entry in the vhosts file isn't enough.

For example, for the "somedomain.com" vhost in the example above to work, I added this to http.conf:

#This must match with the same location as DocumentRoot in httpd-vhost.conf.
<Directory "/home/normaluser/somedomain.com/htdocs">
    #Put whatever directives you want in here
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

Let me know if you need any clarification. wink

Last edited by trusktr (2012-04-13 06:16:02)


joe@trusktr.io - joe at true skater dot io.

Offline

Board footer

Powered by FluxBB