Fedora Core – virtual hosts httpd
I’ve reinstalled my pc with Fedora Core recently, because of the extended SELinux and more tools that are at my disposal. A problem I always had with ubuntu was the configuration of Apache virtual hosts. Once they where installed I needed to put them into the host file and each time I reconnected to a network the NetworkManager rewrote the hosts file annoying me and the fact that if one was configured localhost would also begin pointing to it, a rather nasty thing.
First you need to open the console and login with your root user, type su and fedora will already know what to do.
You need to shutdown the httpd servic deamon with the command :
1 /etc/init.d/httpd stop
You will have to open /etc/httpd/conf/httpd.conf, once opened you will have to locate the section on virtual hosts and you should see an example that is already commented out., I edited the files with nano in the console.
1 ### Section 3: Virtual Hosts
Instead of telling you which lines to uncomment, I’m going to show you below, the stanzas to add to the Virtual Host section to get companyABC.com and companyDEF.com websites running:
001 #002 # Virtual hosts003 #004 005 # Virtual host Default Virtual Host006 <VirtualHost *>007 DocumentRoot /var/www/html/008 ErrorLog logs/error_log009 ServerAdmin root@localhost010 011 012 013 ServerSignature email014 TransferLog logs/access_log015 DirectoryIndex index.php index.html index.htm index.shtml016 017 018 SSLEngine off019 SSLCertificateFile /etc/pki/tls/certs/localhost.crt020 SSLCertificateKeyFile /etc/pki/tls/private/localhost.key021 022 SSLCACertificateFile /etc/pki/tls/certs/ca-bundle.crt023 024 SSLOptions025 LogFormat "None"026 TransferLog logs/access_log027 ErrorLog logs/error_log028 LogLevel debug029 HostNameLookups off030 031 032 033 034 </VirtualHost>035 036 # Virtual host resume.loc037 <VirtualHost 127.0.0.1>038 DocumentRoot /var/www/html/mdw/resume039 ErrorLog logs/error_log040 ServerAdmin root@localhost041 ServerName resume.loc042 043 044 ServerSignature email045 TransferLog logs/access_log046 DirectoryIndex index.html index.php index.shtml047 048 <Directory "/var/www/html/mdw/resume/">049 Options all050 051 AllowOverride all052 053 054 055 </Directory>056 057 058 SSLEngine off059 SSLCertificateFile /etc/pki/tls/certs/localhost.crt060 SSLCertificateKeyFile /etc/pki/tls/private/localhost.key061 062 SSLCACertificateFile /etc/pki/tls/certs/ca-bundle.crt063 064 SSLOptions065 LogFormat "None"066 TransferLog logs/access_log067 ErrorLog logs/error_log068 LogLevel error069 HostNameLookups on070 071 072 073 074 </VirtualHost>075 076 # Virtual host linker077 <VirtualHost 127.0.0.1>078 DocumentRoot /var/www/html/mdw/linkerv2/079 ErrorLog logs/error_log080 ServerAdmin root@localhost081 ServerName linker.loc082 083 084 ServerSignature email085 TransferLog logs/access_log086 DirectoryIndex index.html index.php index.shtml087 088 089 SSLEngine off090 SSLCertificateFile /etc/pki/tls/certs/localhost.crt091 SSLCertificateKeyFile /etc/pki/tls/private/localhost.key092 093 SSLCACertificateFile /etc/pki/tls/certs/ca-bundle.crt094 095 SSLOptions096 LogFormat "None"097 TransferLog logs/access_log098 ErrorLog logs/error_log099 LogLevel error100 HostNameLookups on101 102 103 104 105 </VirtualHost>106 107 # Virtual host Virtual Host 1108 <VirtualHost 127.0.0.1>109 DocumentRoot /var/www/html/mdw/site110 ErrorLog logs/error_log111 ServerAdmin root@localhost112 ServerName mdw.loc113 114 115 ServerSignature email116 TransferLog logs/access_log117 DirectoryIndex index.html index.php index.shtml118 119 120 SSLEngine off121 SSLCertificateFile /etc/pki/tls/certs/localhost.crt122 SSLCertificateKeyFile /etc/pki/tls/private/localhost.key123 124 SSLCACertificateFile /etc/pki/tls/certs/ca-bundle.crt125 126 SSLOptions127 128 TransferLog logs/access_log129 ErrorLog logs/error_log130 LogLevel error131 HostNameLookups on132 133 134 135 136 </VirtualHost>137 138
After you have added the host(s), save the file. At this point, you will need to add the appropriate records to your DNS server to make these domains reachable by anyone on the network. If you have no access to a DNS server (BIND9), or you just want to test the configuration, just edit your /etc/hosts file. Here is what my file looks like:
1 # Do not remove the following line, or various programs2 # that require network functionality will fail.3 127.0.0.1 localhost.localdomain localhost4 127.0.0.1 host1.loc5 127.0.0.1 host2.loc6
Once hosts is saved you just restart your server and everything should work without a problem
webscriptz 11:47 on 30/03/2011 Permalink |
This is if you have a server distribution installed on a laptop like I do for development purposes.
Note that this works best with a server distribution because,if you take, for instance the Ubuntu desktop edition an make a webserver for development purposes you will have disable NetworkManager
or each time you connect to a different network rewrite the /etc/hosts to be able to access your websites via the link specified by you.
Fedora, RHEL and centOS use /etc/resolv.conf for the IP-address currently used by the PC where Ubuntu for instance use /etc/hosts and thus rewrites it as soon as you change from network.
webscriptz 23:09 on 30/03/2011 Permalink |
A friend pointed out that When in production you should patch the server, here’s a good article describing howto: http://mitka.us/articles/mpm-itk/