In this tutorial I will explain what basic Apache Virtual host directives mean and how you can change their values in order to suit your needs. The directives that I will speak about are: VirtualHost, ServerAdmin, ServerName, ServerAlias, DocumentRoot, ErrorLog and CustomLog.
Code used during this tutorial:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# Apache Virtual host explained sudo vi /etc/apache2/sites-available/http.liviubalan.com.conf :0,$d # Contains directives that apply only to a specific hostname or IP address # Syntax: <VirtualHost addr[:port] [addr[:port]] ...> ... </VirtualHost> <VirtualHost *:80> # Optional. You can get this value in PHP using $_SERVER['SERVER_ADMIN'] ServerAdmin admin@liviubalan.com # Required. Base domain that should match for this virtual host # This will most likely be your domain (usually without www) ServerName http.liviubalan.com # Optional. Defines further names that should match as if they were the base name # This is useful for matching hosts you defined, like www ServerAlias www.http.liviubalan.com ServerAlias test.com *.test.com # Required. Sets the directory from which Apache will serve files # Example: DocumentRoot "/usr/web". An access to http://my.example.com/index.html refers to /usr/web/index.html # The DocumentRoot should be specified without a trailing slash DocumentRoot /var/www/http.liviubalan.com # Required. Location where the server will log errors ErrorLog ${APACHE_LOG_DIR}/error.log #ErrorLog /var/log/apache2/http.liviubalan.com-80-error.log #ErrorLog /var/log/apache2/http.liviubalan.com-error.log # Required. Log requests to the server # Syntax: CustomLog log_location log_format # "combined" internal Apache specification: sudo vi /etc/apache2/apache2.conf # Useful URL: http://httpd.apache.org/docs/2.2/mod/mod_log_config.html#formats CustomLog ${APACHE_LOG_DIR}/access.log combined #CustomLog /var/log/apache2/http.liviubalan.com-80-access.log combined #CustomLog /var/log/apache2/http.liviubalan.com-access.log combined </VirtualHost> # Restart Apache sudo service apache2 restart # Browser http://http.liviubalan.com/ http://www.http.liviubalan.com/ http://test.com/ http://www.test.com/ http://http.test.com/ # Local operating system sudo vi /etc/hosts 192.168.56.101 http.liviubalan.com www.http.liviubalan.com 192.168.56.101 wp.liviubalan.com 192.168.56.101 liviubalan.ro 192.168.56.101 test.com www.test.com http.test.com tail -f /var/log/apache2/error.log tail -f /var/log/apache2/http.liviubalan.com-80-error.log tail -f /var/log/apache2/http.liviubalan.com-error.log tail -f /var/log/apache2/access.log tail -f /var/log/apache2/http.liviubalan.com-80-access.log combined tail -f /var/log/apache2/http.liviubalan.com-access.log combined # Browser http://http.liviubalan.com/ http://wp.liviubalan.com/ Useful links: https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts |
Useful links:
https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts