I would like to have multiple domains going to the same EC2 instance. All will have same IP. I have setup multiple vhost files as domain1.com and domain2.com. I do not have anything special in any htaccess files or in the vhost files. I have the domains through GoDaddy, they are pointed to the EC2 IP. The issue I have is that both domain 1 and 2 go to the same folder and show the same index.html in the browser.
As per https://help.ubuntu.com/lts/serverguide/httpd.html I see that httpd.conf does not exist anymore and I do not see anything in apache2.conf for ghosts.
(As you can see the commented out things I have tried)
* NOT using rout 53, I do not want to use this, unless I have too*
vhost files:
(domain 1)
#SSLStaplingCache shmcb:/tmp/stapling_cache(128000)
SSLStaplingCache shmcb:${APACHE_RUN_DIR}/ssl_stapling_cache(128000)
<VirtualHost *:80>
ServerAdmin me#localhost
ServerName domain1.com
ServerAlias www.domain1.com
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
SSLUseStapling on
RewriteEngine on
#RewriteRule domain1.com\/$ http://domain1.com [NC]
RewriteCond %{SERVER_NAME} =domain1.com [OR]
RewriteCond %{SERVER_NAME} =domain1.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
(domain 2)
<VirtualHost *:80>
ServerAdmin me#gmail.com
ServerName domain2.com
ServerAlias www.domain2.com
DocumentRoot /var/www/html/domain2.com
# ServerPath "/domain2.com/"
# RewriteEngine On
# RewriteRule "^(/domain2.com/.*)" "/html/domain2.com$1"
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/html/domain2.com>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
#RewriteEngine on
#RewriteRule domain2.com\/$ http://domain2.com/index.php [NC]
</VirtualHost>
default-ssl.conf file:
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin me8#gmail.com
ServerName domain1.com
DocumentRoot /var/www/html/domain1.com
*********** EDIT ****************
apache2 -v
Server version: Apache/2.4.18 (Ubuntu)
Server built: 2017-09-18T15:09:02
sudo apachectl configtest
Syntax OK
I have completed "sudo a2ensite" command on vhost files and restarted apache after them
******* EDIT ****************
in hosts:
127.0.0.1 localhost
127.0.1.1 domain1.com
127.0.1.2 domain2.com
You should provide more details:
What Instance/LAMP are you using?
Are you configuring vhost correctly?
For Bitnami stacks, for example, you should add the correct add the following line to the end of /opt/bitnami/apache2/conf/bitnami/bitnami-apps-vhosts.conf:
Include "/path to your configuration file.conf”
restart apache:
$sudo /opt/bitnami/ctlscript.sh restart apache
For plain Ubuntu,(after having apache installed) you should include your configuration file as below:
/etc/apache2/sites-available/example.com.conf
ensure to enable your virtual host file:
$sudo a2ensite example.com.conf
restart apache:
$sudo service apache2 restart
So, after making a new instance I was able to set up multiple vhosts.They are all working. The issue must have been the let's encrypt cert. I will backup my configuration and try let's encrypt on this the instance. I will report my findings to this posting. Thank you all for your help on this.
Related
I have an ubuntu 22.04 webserver on which i have configured php, mariadb, apache2 stack.
I then deployed a laravel project, which works fine, under the path.
/var/www/html/site1.it
So now I created a project under the path /var/www/html/site2.it and re-executed the same steps done for site1.
So I created the site2.conf, entered the configuration and restarted apache2.
On my mac in the hosts file I then set the IP <-> site pair to reach the site via domain.
However, when I type the url http://site2.it on the browser, I call site1.it
Do you have any suggestions or advice?
EDIT: Steps to configure Apache2 site
I've followed this tutorial:
Deploy Laravel on Apache server
apache site1.conf file:
<VirtualHost *:80>
ServerAdmin site1#localhost
ServerName site1
ServerAlias site1.it
DocumentRoot /var/www/html/site1.it/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =site1.it [OR]
RewriteCond %{SERVER_NAME} =site1
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
#<VirtualHost *:443>
# DocumentRoot /var/www/html/site1.it/public
# ServerName site1
# ServerAlias www.site1.it
# SSLEngine on
# SSLCertificateFile /home/
# SSLCertificateKeyFile /home
#
# <Directory /var/www/html/site1.it/public>
# Order allow,deny
# AllowOverride All
# Allow from all
# </Directory>
#</VirtualHost>
I successfully deployed a Laravel application on Apache Ubuntu 20.04 in Digital Ocean, everything was fine until I installed CertBot software to configure HTTPS on my Apache server. After installing and setting up certbot, when i visit the homepage via HTTPS:// link, it works fine but when I tried to visit other pages via HTTPS:// link, i get the error below:
Not Found
The requested URL was not found on this server. Apache/2.4.41 (Ubuntu) Server at mysite.com Port 443
I followed the guide in this link: https://www.digitalocean.com/community/tutorials/how-to-secure-apache-with-let-s-encrypt-on-ubuntu-20-04
Below is my Apache Config files
mysite.com.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName mysite.com
ServerAlias www.mysite.com
DocumentRoot /var/www/mysite.com/mysite-web-app/public
<Directory /var/www/mysite.com/mysite-web-app/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<IfModule mod_dir.c>
DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
</IfModule>
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.mysite.com [OR]
RewriteCond %{SERVER_NAME} =mysite.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
mysite.com-le-ssl.conf
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin webmaster#localhost
ServerName mysite.com
ServerAlias www.mysite.com
DocumentRoot /var/www/mysite.com/mysite-web-app/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/mysite.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mysite.com/privkey.pem
</VirtualHost>
</IfModule>
You must include this in the ssl conf as well:
<Directory /var/www/mysite.com/mysite-web-app/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
<IfModule mod_dir.c>
DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
</IfModule>
Or the .htaccess won't work for https connections.
I have a locally created laravel RESTFUL API and I deployed it on my ec2 ubuntu server using git.
I've set it like my main website.. /var/www/api.myapp.com/public_html/myapp-be and for its config I have this /etc/apache2/sites-available/api.myapp.com.conf.
Almost all blogs and tutorials that I found about deploying laravel on apache2 ubuntu server were almost the same and I've followed them all. However, when I test my API on postman with https://api.myapp.com/api/somefunctionhere it says 404 not found, The requested URL was not found on this server. Apache/2.4.29 (Ubuntu) Server at api.myapp.com port 443.
But when I test my local api on postman, it works fine, thus, I confirm that nothing is wrong with my laravel.
My config looks like this
<VirtualHost *:80>
<Directory /var/www/api.myapp.com/public_html/myapp-be/public/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
Require all granted
</Directory>
ServerAdmin developer#myapp.com
ServerName api.myapp.com
Redirect permanent / https://api.myapp.com/
ServerAlias api.myapp.com
DocumentRoot /var/www/api.myapp.com/public_html/myapp-be/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/error.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =api.myapp.com [OR]
RewriteCond %{SERVER_NAME} =api.myapp.com
RewriteRule ^ https://${SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<VirtualHost *:443>
<Directory /var/www/api.myapp.com/public_html/myapp-be/public/>
AllowOverride All
</Directory>
ServerName api.myapp.com
DocumentRoot /var/www/api.myapp.com/public_html/myapp-be/public
</VirtualHost>
Is there a spot that I missed here? Obviously I missed a spot but I've been looking for it for almost 3hours already and still wont work.
Any idea guys? Thanks!
UPDATE: I tried adding /public to the prefix and it worked, I don't even know why it worked - https://api.myapp.com/public/api/somefunctionhere
I want to create a virtual host for a laravel site. I followed the steps until sudo a2ensite www.staysure-wb.local.conf and it displays as the site is enabled. Site www.staysure-wb.local already enabled
But when I open the browser as www.staysure-wb.local it doesn't work.
I tried these commands after enabling site too. But it doesn't load in the browser.
sudo systemctl restart apache2
sudo service apache2 reload
sudo service apache2 restart
Here is my www.staysure-wb.local.conf file.
<VirtualHost *:80>
ServerName staysure-wb.local
ServerAlias *.staysure-wb.local
DocumentRoot /home/mayuri/Documents/projects/staysure-wb/public
<Directory /home/mayuri/Documents/projects/staysure-wb/public>
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost 127.0.0.28:443>
SSLEngine on
ServerName staysure-wb.local
ServerAlias *.staysure-wb.local
DocumentRoot /home/mayuri/Documents/projects/staysure-wb/public
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
ErrorLog ${APACHE_LOG_DIR}/error.log
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
#Header set X-Frame-Options SAMEORIGIN
<Directory /home/mayuri/Documents/projects/staysure-wb/public>
php_admin_flag engine on
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
RewriteEngine On
RewriteOptions Inherit
Require all granted
</Directory>
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel debug
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
The site is available in /etc/apache2/sites-available as follows.
-rwxr-xr-x 1 root root 1240 Mar 26 10:02 www.staysure-wb.local.conf*
Here is the entry what I wrote in the hosts file:
126.0.0.1 localhost
127.0.0.28 www.staysure-wb.local
0.0.0.0 account.jetbrains.com
0.0.0.0 www.jetbrains.com
0.0.0.0 https://account.jetbrains.com:443
0.0.0.0 www-weighted.jetbrains.com
1.2.3.4 account.jetbrains.com
1.2.3.4 http://www.jetbrains.com
1.2.3.4 www-weighted.jetbrains.com
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
When I try to load www.staysure-wb.local in the browser url bar, it returns to Google search bar as follows. image
Help me to load the site in the browser. Thank you.
If you are sharing a screenshot of the error message that's more helpful to answer.
Did you use vagrant? If yes, The following steps are helpful to you.
Add the content in /etc/apache2/sites-available/www.staysure-wb.local.conf
Make ensure the project folder path is correct or not
<VirtualHost *:80>
DocumentRoot "/vagrant/locify/web"
ServerName locify.local
<Directory "/vagrant/locify/web">
RewriteEngine on
# If a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward it to index.php
RewriteRule . index.php
AllowOverride All
Require all Granted
</Directory>
</VirtualHost>
Enable the conf file
sudo a2ensite www.staysure-wb.local.conf
Enable rewrite module
sudo a2enmod rewrite
Add the host entry in your local hosts file
<IP address> www.staysure-wb.local
after successfully installing XAMP and then typo3 on my Mac, I set up a virtual host to avoid typing long URL when working on TYPO3.
I uncommented the http.conf line dealing with http-vhosts.conf so that I could set up virtual hosts, then I added my virtual host (called typo3dev) in httpd-vhosts.conf and I finally edited my hosts file accordingly.
So far so good, BUT now the issue that I'm having is that while pointing to the BE ( with http://typo3dev/typo3/ ) works just fine (I am able to log in and have fun in there), I cannot see the Frontend:
When pointing my browser to http://typo3dev/ , I get redirected to http://typo3dev/get-started/ where I get a Page Not Found error
Looking at the server error logs in I get that
$[Thu Jun 21 12:39:20 2012] [error] [client 127.0.0.1] File does not exist: /Applications/XAMPP/htdocs/typo3/introductionpackage-4.7.1/get-started
By the way, my hosts file looks like this:
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
127.0.0.1 typo3dev
my httpd-vhosts.conf like that:
NameVirtualHost *:80
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
DocumentRoot "/Applications/XAMPP/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Applications/XAMPP/htdocs/typo3/introductionpackage-4.7.1"
ServerName typo3dev
</VirtualHost>
Thank you very much in advance for any help/ comment/ advice
Cheers
This looks like a RealURL/Apache configuration problem to me. Make sure that you allow .htaccess in your Apache configuration ...
<VirtualHost *:80>
DocumentRoot "/Applications/XAMPP/htdocs/typo3/introductionpackage-4.7.1"
ServerName typo3dev
<Directory /Applications/XAMPP/htdocs/typo3/introductionpackage-4.7.1>
AllowOverride all
Order allow,deny
allow from all
</Directory>
</VirtualHost>
... or configure the RewriteRules directly in the VirtualHost section.
<VirtualHost *:80>
DocumentRoot "/Applications/XAMPP/htdocs/typo3/introductionpackage-4.7.1"
ServerName typo3dev
<Directory /Applications/XAMPP/htdocs/typo3/introductionpackage-4.7.1>
AllowOverride None
Order allow,deny
allow from all
</Directory>
<Directory /Applications/XAMPP/htdocs/typo3/introductionpackage-4.7.1>
RewriteEngine On
RewriteRule ^/(typo3|typo3temp|typo3conf|t3lib|tslib|fileadmin|uploads|showpic\.php)$ - [L]
RewriteRule ^/(typo3|typo3temp|typo3conf|t3lib|tslib|fileadmin|uploads|showpic\.php)/.*$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L]
</Directory>
</VirtualHost>
Remember to reload / restart Apache after making changes to the configuration.
It's seems to me like you have installed the wrong package. Install only the source package because all other package is for demo. Also if you can avoid Apache. It's complicated and bloated. I can recommend lighttpd. It's much easier to configure especially with virtual domains.