Configure apache, set multiple virtualhost on EC2 AWS - apache

I'm trying to mount an AWS server with 2 different projects. The specification of the AMI is this
Platform: Amazon Linux (inferred)
Details of platform: Linux/UNIX
All the AMI configuration is done, the 80 port is avaible. The IP is this http://13.59.121.162/
I'm using apache to serve the files.
I tried to find the folder /etc/apache2/sites-available but this distribution has not that directory. I have not idea how to create it manually and the inside files. I found this file
/etc/httpd/conf/httpd.conf
And I edited and added a new VirtualHost lines
<VirtualHost *:80>
ServerAdmin foo#bar.com
DocumentRoot /var/www/html/food
ServerName 13.59.121.162/food
ErrorLog logs/food-error_log
CustomLog logs/food-access_log common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin foo#bar.com
DocumentRoot /var/www/html/backoffice
ServerName 13.59.121.162/admin
ErrorLog logs/admin-food-error_log
CustomLog logs/admin-food-access_log common
</VirtualHost>
The apache's directory structure is this
/var
/www
/html
/backoffice
-index.html <-- <h1>Aquí backoffice</h1>
/food
-index.html <-- <h1>Aquí la comida</h1>
I visited http://13.59.121.162/food but I have an error (ERR_CONNECTION_TIMED_OUT) Can't access to this website. I hope to see Aquí la comida, but nothing. I have the same error with the other configuration, but if I visit http://13.59.121.162 it shows Aquí la comida
What did I do wrong?

nowhere in your configuration have you granted access, you need to grant access to the directories,, something like this...
<VirtualHost *:80>
<Directory /var/www/html/food>
Require All Granted
</Directory>
</VirtualHost>

Related

Apache2 ServerName and ServerAlias not working

On a nearly fresh Ubuntu 20.04 LTS computer, I would like to set up a virtual host on my local machine. So I created a index.html under /var/www/test/ with the following content:
you have entered a test page
I have set up a test.conf file under /etc/apache2/sites-available/
with the following content:
<VirtualHost *:80>
ServerAdmin webmaster#zhihu.com
DocumentRoot /var/www/test/
ServerName zhihu.com
ServerAlias www.zhihu.com
<Directory /var/www/test/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
The localhost is working:
/etc/hosts config is probably working as indicated by ping
ping zhihu.com
PING zhihu.com (127.0.1.1) 56(84) bytes of data.
64 bytes from xxx (127.0.1.1): icmp_seq=1 ttl=64 time=0.045 ms
but browser cannot bring me to the domain which should now be hosted in /var/www/test/.
I have also a2ensite test.conf and a2dissite 000-default.conf and service apache2 reload
So I think the only possible place for error to occur is ServerName and ServerAlias. Why are they not working?
Could you please enable VirtualHost using a2ensite and access site in incognito mode.
Ensure that the ssl certificate for the site includes both example.com and www.example.com
and ServerAlias is set to www.example.com

Hosting another website on linux AMAZON EC2 intance running bitnami wordpress

I have an EC2 instance created with Bitnami wordpress, I am trying to host my other website on the same instance website.tld
I followed the steps on this guide
https://docs.bitnami.com/aws/components/apache/#how-to-create-a-virtual-host
Then I went to "/opt/bitnami/apps/wordpress/conf/httpd-vhosts.conf" and changed it to
<VirtualHost *:80>
ServerName mywordpress.com
ServerAlias mywordpress.com
DocumentRoot "/opt/bitnami/apps/wordpress/htdocs"
Include "/opt/bitnami/apps/wordpress/conf/httpd-app.conf"
</VirtualHost>
<VirtualHost *:80>
ServerName website.tld
ServerAlias www.website.tld
DocumentRoot "/opt/bitnami/apps/website/htdocs"
ErrorLog "logs/website-error_log"
CustomLog "logs/website-access_log" common
</VirtualHost>
<VirtualHost *:443>
ServerName mywordpress.com
ServerAlias www.mywordpress.com
DocumentRoot "/opt/bitnami/apps/wordpress/htdocs"
SSLEngine on
SSLCertificateFile "/opt/bitnami/apps/wordpress/conf/certs/server.crt"
SSLCertificateKeyFile "/opt/bitnami/apps/wordpress/conf/certs/server.key"
Include "/opt/bitnami/apps/wordpress/conf/httpd-app.conf"
</VirtualHost>
I created the empty folders "/opt/bitnami/apps/website/htdocs" for my new website then added an index.html inside htdocs
Then I restarted the apache server
sudo /opt/bitnami/ctlscript.sh restart apache
mywordpress.com works fine as before, but when i try to open website.tld I get this error
Forbidden
You don't have permission to access / on this server.
Am i doing it wrong? is there any other configurations i missed?
What is more confusing is there are httpd-vhosts.conf files inside the apache2 server and inside each folder in the apps/ folder, I am not sure which of all I should be adding my new domain tag into? Following the bitnami docs I edited the one inside apps/wordrpess/config
I am not a server side guy, is there a UI for the apache server that can help me setup the virtual host?
Thank you in advance.
You have to set the permissions for this directory in apache2.conf/ httpd.conf.
<Directory [your path]>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
And set the permissions with chmod 755

Set DocumentRoot on local directory in apache

I got a local directory, which will need a DocumentRoot.
When I go to serverip/nivon-zuidholland I must have a DocumentRoot of public.
How would I manage this in apache2 config?
I inserted this in my apache2.conf. I tried to put this into my sites-available/nivon-zuidholland.conf but this doesn't work as well.
I can't restart apache2 because it returns DocumentRoot not allowed here.
<Directory "/var/www/html/nivon-zuidholland">
AllowOverride All
DocumentRoot /var/www/html/nivon-zuidholland/public
</Directory>
In your /etc/hosts add this:
127.0.0.1 nivon-zuidholland.local
Create a directory: /var/www/nivon-zuidholland (set group to www-data)
Create a Virtual host file: /etc/apache2/sites-available/nivon-zuidholland.conf
<VirtualHost *:80>
ServerName nivon-zuidholland.local
ServerAdmin webmaster#nivon-zuidholland.local
DocumentRoot /var/www/nivon-zuidholland
ErrorLog ${APACHE_LOG_DIR}/nivon-zuidholland_error.log
CustomLog ${APACHE_LOG_DIR}/nivon-zuidholland.log combined
</VirtualHost>
Place a symbolic link to this vhost conf file in sites-enabled directory
ln -s /etc/apache2/sites-available/nivon-zuidholland.conf /etc/apache2/sites-enabled/nivon-zuidholland.conf
Restart Apache server: sudo service apache2 restart
You should be able to access the site by going to: http://nivon-zuidholland.local/

Setup vhost ubuntu

I am trying to setup a vhost in ubuntu, my file is like
/var/www/vhost/domain1.com/app
/var/www/vhost/domain1.com/public
/var/www/vhost/domain2.com/app
/var/www/vhost/domain2.com/public
the vhost in /etc/apache2/site-avalable/domain1.com.conf is :
<virtualhost *:80>
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
ServerAdmin webmaster#domain1.com
ServerName domain1.com
ServerAlias *.domain1.com
DirectoryIndex index.php
DocumentRoot /var/www/vhosts/domain1.com/public
LogLevel warn
ErrorLog /var/www/vhosts/domain1.com/log/error.log
CustomLog /var/www/vhosts/domain1.com/log/access.log combined
</virtualhost>
problem
the vhost folder and all the files after that (the children) are accessible in the web browser. I know I have to put some sort of htaccess but i don't know how and where I have to put it.
If you use apache 2.4 and you develop on a local machine:
Create a new configuration file for your website:
$ sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/domain1.com.conf
Edit the file like so:
<VirtualHost *:80>
ServerName domain1.com
ServerAlias *.domain1.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/vhost/domain1.com/public
ErrorLog /var/www/vhosts/domain1.com/log/error.log
CustomLog /var/www/vhosts/domain1.com/log/access.log combined
</VirtualHost>
Enable the website
$ sudo a2ensite domain1.com
Restart apache
$ sudo service apache2 restart
Add the following line to your /etc/hosts file
127.0.1.1 domain1.com
Now it should work, go to http://domain1.com and check it out.

VirtualHost on Apache Server -- CentOS

I am new to Apache server and would appreciate any help from you guys regards to VirtaulHost.
Context: I am setting up a CA/Web Server on CentOS 5.8 with Apache Server and I would like to have a public accessibility to my CRL
Network Configurations: eth0 - Private Interface: 10.10.10.2, eth1 - Public Interface: 199.200.201.202 (fake one of course :P)
Current Configuration in "httpd.conf":
<VirtualHost 10.10.10.2:80>
ServerAdmin a#aa.com
DocumentRoot /var/www/html
ErrorLog logs/CA-Test.abc.net
CustomLog logs/CA_Custom_logs common
</VirtualHost>
<Directory />
Order allow, deny
Allow from all
AllowOverride all
</Directory>
URL for CRL Location: "CA-Test.abc.net\ca\crl\root.crl"
Question\Problem: I would like to allow public access to the "\ca\crl" directory only, but not the contents under parent directories "\ca"
Should my VirtualHost Configuration to be:
<VirtualHost 199.200.201.202:80>
ServerAdmin a#aa.com
DocumentRoot /ca/crl/root.crl
ErrorLog logs/CA-Test.abc.net
CustomLog logs/CA_Custom_logs common
</VirtualHost>
If not, What should the correct DocumentRoot to be in this case? (/var/www/html/ca/crl/root.crl??) How should I configure it correctly to allow external access to the correct URL of CRL location?
Thank you for your time and help.. :)
try adding these to your httpd.conf
<VirtualHost IP:80>
DocumentRoot /fullpath/to/ca/crl/
ServerName CA-Test.abc.net
</VirtualHost>
Now restart your httpd and try browsing the url
http://CA-Test.abc.net/root.crl
Now public can't access the contents in the folder "ca". Let us know if that helped you.