logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in  RSS Apache Lounge  


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.


Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Hosting 2 websites on single Apache webserver/Static IP
Author
snsapache



Joined: 06 Jan 2021
Posts: 4

PostPosted: Wed 06 Jan '21 21:43    Post subject: Hosting 2 websites on single Apache webserver/Static IP Reply with quote

Happy New Years to all. Newb here and to Apache.

I have chosen to install a LAMP stack along with Wordpress on top of an Amazon Linux 2 Lightsail instance. I am choosing to do this because it is the most cost effective and least wasteful of resources for what will be low traffic personal sites. Secondly, Wordpress Multisite does not work for my needs as my sites will have different themes/plugins and just overall makes management easier.

I was able to install LAMP along with Wordpress for a single website successfully.

However, I am stuck trying to add a second Wordpress instance on to the same server and getting it to connect properly. Many of the walkthroughs I found mention to create a copy of the Apache config file and place it in to the respective subdirectory of each individual website I want to host. From there, make the necessary edits within the config file to point to the correct domain. Then finally, disable the default config file and enable the new ones.

My problem is I believe the Apache distribution installed on Amazon Linux 2 is different so the walkthroughs I find don't help me much. The first thing that's different is I do not have the sites-enabled or sites-available subdirectories that the walk throughs direct me to create my website subdirectories in. (My default Apache config file is located in/etc/httpd/conf/httpd.conf)

Secondly, I do not have the commands a2enmod and a2ensite available to disable and enable the old and new apache config files.

My questions:

Where should I create my website subdirectories and new config files? Within /etc/httpd/conf?

How do I enable the updated config files so it runs?

Does anyone have any guidance for this? Much appreciate any and all help.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 6907
Location: Germany, Next to Hamburg

PostPosted: Thu 07 Jan '21 9:42    Post subject: Reply with quote

You can use name based virtual hosts[1]

See for an example see here[2]

You still need to set up DNS

[1] https://httpd.apache.org/docs/2.4/vhosts/name-based.html#using

[2] https://gist.github.com/JBlond/3d58a1a2e66ce0e42413d9015377a72c
Back to top
snsapache



Joined: 06 Jan 2021
Posts: 4

PostPosted: Mon 11 Jan '21 3:40    Post subject: Reply with quote

Thanks James Blond. I tore down the instance and started over again.

Here are the steps Iíve taken:

-created two database users and databases
-created two subdirectories: /var/www/html/website1 and /var/www/html/website2
-installed wordpress in each subdirectory
-edited each wp-config.php to point to each domainís database user and database
-installed and ran certbot for SSL. Certbot successfully created and deployed certificates. It created a new and separate SSL vhost conf file that points to both domains.
-set up my static IP A Record within each domainís DNS for website1 and website2
-edited apacheís httpd.conf file:

Code:
<VirtualHost *:80>
DocumentRoot "/var/www/html/website1"
ServerName website1.com
ServerAlias www.website1.com
</VirtualHost>

<VirtualHost *:80>
DocumentRoot "/var/www/html/website2"
ServerName website2.com
ServerAlias www.website2.com
</VirtualHost>


Here are the issues Iím having:

-For SSL, when visiting the sites for the first time they came back secure, but now when revisiting, shows not secureÖ might be a cache issue
-visiting http://staticIP# directs to website1
-visiting http://staticIP#/website1 and http://staticIP#/website2 comes back with the correct home pages, however the formatting is way off. There isnít any colors or margins. Everything is squished together and in plain text
-publishing changes in WP only show correctly on the computer Iím using within the editor, but on all other browsers show no formatting and is in plain text.

I feel like Iím very close to getting things set up and pointed correctly, but Iím obviously missing some key steps. Any insight would be appreciated.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 6907
Location: Germany, Next to Hamburg

PostPosted: Tue 12 Jan '21 9:17    Post subject: Reply with quote

For each 80 vhost you need a second 443 vhost to have SSL working correctly. [1]

Sure that IP/website does not work correctly since wordpress uses the domain name in the path to the files.


[1]
Code:

<VirtualHost *:80>
   ServerName example.com
   DirectoryIndex index.html
   CustomLog "C:\nul" common

   DocumentRoot "C:/htdocs"
   <Directory "C:/htdocs">
      Options Indexes FollowSymLinks
      AllowOverride All
      Require all granted
   </Directory>
</VirtualHost>

<VirtualHost *:443>
   ServerName example.com
   DirectoryIndex index.html
   CustomLog "C:\nul" common

   DocumentRoot "C:/htdocs/example"
   <Directory "C:/htdocs/example">
      Options Indexes FollowSymLinks
      AllowOverride All
      Require all granted
   </Directory>
   
   SSLEngine on
   SSLCertificateFile conf/certs/fullchain.pem
   SSLCertificateKeyFile conf/certs/privkey.pem

   <Files ~"\.(cgi|shtml|phtml|php|htm|html?)$>
      SSLOptions +StdEnvVars
   </Files>
</VirtualHost>
Back to top
snsapache



Joined: 06 Jan 2021
Posts: 4

PostPosted: Tue 12 Jan '21 9:26    Post subject: Reply with quote

Thank you James Blond.

I added the 443 vhosts to the httpd config file under the 80 vhost for each domain. I copied some of the code over from the separate vhost config file that the certbot created assuming the syntax was correct. Some of the other syntax was also auto populated on its own. It's not working. This is what I have in the code block:

Code:
Listen 80
Listen 443

<VirtualHost *:80>

   DocumentRoot "/var/www/html/website1"
   ServerName website1.com
   ServerAlias www.website1.com

RewriteEngine on
RewriteCond %{SERVER_NAME} =www.website1.com [or]
RewriteCond %{SERVER_NAME} =website1.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END , NE, R=permanent]

</VirtualHost>

<VirtualHost *:443>

   DocumentRoot "/var/www/html/website1"
   ServerName website1.com
   ServerAlias www.website1.com

Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/website1.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/website1.com/privkey.pem

</VirtualHost>

<VirtualHost *:80>

   DocumentRoot "/var/www/html/website2"
   ServerName website2.com
   ServerAlias www.website2.com

RewriteEngine on
RewriteCond %{SERVER_NAME} =www.website2.com [or]
RewriteCond %{SERVER_NAME} =website2.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END , NE, R=permanent]

</VirtualHost>

<VirtualHost *:443>

   DocumentRoot "/var/www/html/website2"
   ServerName website2.com
   ServerAlias www.website2.com

Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/website1.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/website1.com/privkey.pem"

</VirtualHost>


Regarding your second command on how WordPress uses the domain name in the path to the files, can you expand on this? Not sure I follow.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 6907
Location: Germany, Next to Hamburg

PostPosted: Wed 13 Jan '21 10:21    Post subject: Reply with quote

snsapache wrote:
It's not working.


What is not working? The same error like before?

snsapache wrote:

Regarding your second command on how WordPress uses the domain name in the path to the files, can you expand on this? Not sure I follow.


The paths in the generated HTML code are like
Code:

<link rel='stylesheet' id='wp-block-library-css'  href='https://example.com/wp-includes/css/dist/block-library/style.min.css?ver=5.6' type='text/css' media='all' />


That is why the file won't load.
Back to top
snsapache



Joined: 06 Jan 2021
Posts: 4

PostPosted: Fri 15 Jan '21 3:11    Post subject: Reply with quote

Thanks James Blond.

Quote:
What is not working? The same error like before?


After adding the 443 vhost to the httpd.conf file, visiting either sites comes back with "site can't be reached"

Quote:
The paths in the generated HTML code are like


I see... so us it because it's trying to call on HTTPS which obviously isn't working at the moment? Fixing the vhosts should resolve this problem?

[/quote]
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 6907
Location: Germany, Next to Hamburg

PostPosted: Fri 22 Jan '21 16:31    Post subject: Reply with quote

Please post your config at http://apaste.info/ or http://hastebin.com/
and here the link to it.
Back to top


Reply to topic   Topic: Hosting 2 websites on single Apache webserver/Static IP View previous topic :: View next topic
Post new topic   Forum Index -> Apache