How to configure virtual host change local link?
Serve Multiple Domains By Using Virtual Hosts
Most people serve more than one domain on their Cloud Server. Whether for different domain names or different subdomains of the same domain, the procedure is the same.Our Linux Cloud Servers are built from a minimal installation image, meaning there are no additional applications installed beyond the base Operating System.To begin using your server, you initiate an SSH session to remotely connect to the Cloud Server. In order to make it more useful, you are responsible for installing applications. This can be done by compiling a program from the source code, or more commonly using the Package Manager to install an application from a repository.The most common application installed is a web server, such as Apache or Nginx.In order to serve a website you must set up the rest of the framework to serve your content, and then upload the actual content to your server. This entails installing any databases or Content Management Systems your site requires. For networking, you will need to add appropriate DNS records in the Rackspace Cloud control panel, to let the DNS system and the rest of the Internet know that your site is hosted from a Rackspace Cloud IP address.
Finally, you come to the part that allows your Cloud Server to deliver your websites, and for this you will need to create your sites as virtual hosts within your webserver configuration.
Procedure
Greatly simplified, the procedure for serving a website is as follows:
A browser sends a request to your Cloud Server’s IP address asking for the contents of ‘http://exampledomain.com/’ (your domain name).
Your web server jumps into action and says “Yes! I have something for you matching your request”. The web server does its ‘thing’ and serves up an http representation of your site, which is sent to the requesting browser. The browser then translates the http and parses it to a human-readable form.Simple, right? But how does your web server know what http to serve? If all you are serving is one website from the server, then it will serve the html in your /var/www/html directory, starting with index.html. We’ve all made a “Hello World” page before, right? But having a unique server for every website you want to serve is costly, and an inefficient use of your resources.
Virtual Hosts
This is a sample vhost configuration for Apache, serving domain1.com:
<VirtualHost \*:80>
ServerName domain1.com
ServerAlias www.domain1.com
</VirtualHost>
server {
server_name www.domain1.com;
rewrite ^/(.\*) http://domain1.com/$1 permanent;
}
Each configuration starts slightly differently, but the same principle applies - that particular virtual host will respond to queries for ‘domain1.com’ and ‘www.domain1.com’.
Multiple domains
So, serving different content for different domains is as simple as adding another virtual host.
Let’s say you have a subdomain called ‘blog.domain1.com’ serving a blog.
The basic creation process would be to create a folder in your public_html folder with the relevant files (let’s say a Wordpress install).
A virtual host would be created with the server_name or ServerName as ‘blog.domain1.com’ which would be configured to point to the blog files and folders in your public_html folder.Troubleshooting
This section shows you how to troubleshoot problems with Apache name-based virtual host configurations.
It will show you useful commands for testing your virtual host configuration, how to interpret their output, and how they help fix common virtual host configuration problems.Restart Apache
Before we make a start on learning to diagnose your issue, make sure that you have restarted Apache since the last changes you made to your Apache configuration files:
The output above was produced by the following virtual host file configuration:
NameVirtualHost \*:80 Turns on name-based host resolution and binds the virtual server to IP addresses and ports as in [1] above. The \* is a wildcard specifying all IP addresses.
<VirtualHost \*:80> Configures the first and default virtual host in [2] & [3] above. It is the default because it is the first virtual host whose IP and port matches those in the NameVirtualHost directive before it.
ServerName vh1.example.com
DocumentRoot /var/www/vhosts/vh1
</VirtualHost>
<VirtualHost \*:80> Configures the second virtual host in [4] above.
ServerName vh2.example.com
DocumentRoot /var/www/vhosts/vh2
</VirtualHost>
Now that that you’ve seen how a basic virtual host configuration looks and how it maps to Apache’s own configuration report, let’s use those reports to look at common configuration issues.
How to configure virtual host change local link?
Reviewed by soksopheak
on
12:22 AM
Rating:
No comments: