Apache2 virtual host setup https




















We have a server with two name-based vhosts. In order to match the correct virtual host a client must send the correct Host: header. To provide as much backward compatibility as possible we create a primary vhost which returns a single page containing links with an URL prefix to the name-based virtual hosts. If no Host: header is sent the client gets the information page from the primary host.

The RewriteRule directives are used to make sure that a client which sent a correct Host: header can use both URL variants, i. Copyright The Apache Software Foundation.

Licensed under the Apache License, Version 2. VirtualHost Examples Available Languages: en fr ja ko tr. Running several name-based web sites on a single IP address. Name-based hosts on more than one IP address. Serving the same content on different IP addresses such as an internal and external address. Running different sites on different ports. Note Creating virtual host configurations on your Apache server does not magically cause DNS entries to be created for those host names. Note Any of the techniques discussed here can be extended to any number of IP addresses.

Note: On the internal network, one can just use the name server rather than the fully qualified host name server. IP-based virtual hosting The server has two IP addresses Mixed port-based and ip-based virtual hosts The server machine has two IP addresses Listen Mixed name-based and IP-based vhosts Any address mentioned in the argument to a virtualhost that never appears in another virtual host is a strictly IP-based virtual host.

Migrating a name-based vhost to an IP-based vhost The name-based vhost with the hostname www. Apache - Virtualhost. Apache - LDAP authentication. Apache - Kerberos authentication. Apache - Radius authentication Freeradius. Apache - Radius authentication Active Directory. Apache - Basic authentication. Apache - PAM authentication. Apache - Python CGI. Apache - ModSecurity installation.

Apache - Prevent Hotlinking. Apache - Blocking an IP address list. Apache - Blocking direct access to image. Apache - Disable directory listing. Apache - Disable the Cache. Apache - Change the server identification header. Apache - Proxy. This virtual host section matches any requests that are made on port 80, the default HTTP port.

First, we need to change the ServerAdmin directive to an email that the site administrator can receive emails through. After this, we need to add two directives. The first, called ServerName , establishes the base domain that should match for this virtual host definition.

This will most likely be your domain. The second, called ServerAlias , defines further names that should match as if they were the base name. This is useful for matching hosts you defined, like www :. The only other thing we need to change for our virtual host file is the location of the document root for this domain. We already created the directory we need, so we just need to alter the DocumentRoot directive to reflect the directory we created:.

Now that we have our first virtual host file established, we can create our second one by copying that file and adjusting it as needed.

You now need to modify all of the pieces of information to reference your second domain. When you are finished, it should look like this:. Now that we have created our virtual host files, we must enable them. Apache includes some tools that allow us to do this. If you would like to read more about this script, you can refer to the a2ensite documentation.

When you are finished, you need to restart Apache to make these changes take effect and use systemctl status to verify the success of the restart. This will intercept any requests for the domains that you configured and point them to your VPS server, just as the DNS system would do if you were using registered domains. This will only work from your local computer though, and only for testing purposes. Make sure you are operating on your local computer for these steps and not your VPS server.

If you are on a Mac or Linux computer, edit your local file with administrative privileges by typing:. If you are on a Windows machine, you can find instructions on altering your hosts file here. The details that you need to add are the public IP address of your server followed by the domain you want to use to reach that server. This will direct any requests for example. This is what we want if we are not actually the owners of these domains in order to test our virtual hosts.

Now that you have your virtual hosts configured, you can test your setup by going to the domains that you configured in your web browser:. This will prevent your hosts file from being filled with entries that are no longer necessary. If you need to access this long term, consider adding a domain name for each site you need and setting it up to point to your server.

If you followed along, you should now have a single server handling two separate domain names. You can expand this process by following the steps we outlined above to make additional virtual hosts.



0コメント

  • 1000 / 1000