-1

I have a self hosted apache website with php and mysql on my Raspberry Pi. Now I need to make another one for my new domain but I have no other computer to run the server on. Is there a way for me to run the server on the same machine, with the same port? If not, how may I alter the port so there is no need for me to type example.com:portnumber. I need it to be example.com.

0

Yes you can have two different websites on one machine.

I know of two different possibilites but I'm pretty sure that there are way more out there:

Option 1:

Just run one apache instance and distinguish the domains by Virtual Hosts.

You can create those in /etc/apache2/sites-available and then create a symlink from /etc/apache2/sites-enabled to the respective file you want to enable or use the a2ensite cmd.

For each virtual host create a <Virtual Host>-Block and add the respective ServerName-Tag (your domain name) and the DocumentRoot for the files.

Further reading and examples: Name-based Virtual Host Support

Option 2:

Use a reverse proxy such as nginx. Run this reverse proxy on port 80 and let apache use 2 ports other than 80 (one for each site). As for apache you have to set up multiple server blocks in /etc/nginx/sites-available and enabling them by symlinking from /etc/nginx/sites-enabled.

In this case the reverse proxy also handles https (SSL certificates etc.) and the traffic behind the reverse proxy (only on the local machine) is either entirely unencrypted or encrypted by apache and then decrypted by nginx and reincrypted.

Further reading and examples: NGINX Reverse Proxy

Alternatively you could also use nginx as a webserver on its own for the new website and only reverse-proxy to the "old" site.

I'm not sure if its possible to have to totally independant instances of apache running on the same machine, but I also don't see why this would be necessary. You can change most (if not all) of the needed settings per Virtual Host. If this is possible you could again use nginx (or another reverse proxy) to get both of them accessible from port 80.

0

Yes !

You must create the needed virtual hosts. Each virtual host will answer to its DocumentRoot, with its certificate if it is HTTPS enabled. Remember : the virtual host is based on the host name provided in the URL by the user. In Apache, check in /etc/apache2/site-available/ and copy the existing file and adapt the servername configuration entry. Reload Apache and it work ! Don't forget to create a new entry in your DNS if it is public.

Not the answer you're looking for? Browse other questions tagged or ask your own question.