Author |
|
snsapache
Joined: 06 Jan 2021 Posts: 4
|
Posted: Wed 06 Jan '21 21:43 Post subject: Hosting 2 websites on single Apache webserver/Static IP |
|
|
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: 7371 Location: Germany, Next to Hamburg
|
|
Back to top |
|
snsapache
Joined: 06 Jan 2021 Posts: 4
|
Posted: Mon 11 Jan '21 3:40 Post subject: |
|
|
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: 7371 Location: Germany, Next to Hamburg
|
Posted: Tue 12 Jan '21 9:17 Post subject: |
|
|
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
|
Posted: Tue 12 Jan '21 9:26 Post subject: |
|
|
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: 7371 Location: Germany, Next to Hamburg
|
Posted: Wed 13 Jan '21 10:21 Post subject: |
|
|
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
|
Posted: Fri 15 Jan '21 3:11 Post subject: |
|
|
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: 7371 Location: Germany, Next to Hamburg
|
|
Back to top |
|