VirtualHost on Apache Server -- CentOS - apache

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.

Related

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

Apache and virtual host issues

Feel like I am going slightly mad/round in a circle here so hoping someone can give me some pointers.
I have a Debian instance on AWS running apache. Inside of my /var/www/ folder I have another folder called dineosaw.com. I have a conf file called dineosaw.com.conf which looks like the following
<VirtualHost *:80>
ServerAdmin xxxx#gmail.com
ServerName www.dineosaw.com
ServerAlias dineosaw.com
DocumentRoot /var/www/dineosaw.com/public
<Directory /var/www/dineosaw.com/public>
Options -Indexes
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I then have forwarded my domain name (www.dineosaw.com) to the server by using the following address: http://52.56.144.228/. This however only took me to the apache default page. So I tried: http://52.56.144.228/dineosaw.com/ but this results in a 404 error.
Can anyone give me any pointers as to what I might be doing wrong/need to look in to? I would be very grateful.
If you want to address this name-based virtual host by IP address, you'd need "ServerAlias 52.56.144.228"

Configure Apache to run website off of port-enabled IP address

To be perfectly honest, I'm not even sure if this is doable...
I've configured my vhosts file in /etc/apache2/sites-enabled which you can see here:
<VirtualHost 159.203.171.140:8080>
ServerAdmin webmaster#localhost
ServerName 159.203.171.140:8080
DocumentRoot "/home/wiki/public_html"
DirectoryIndex index.php index.html
<Directory "/home/wiki/public_html">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/wiki_error.log
CustomLog ${APACHE_LOG_DIR}/wiki_access.log combined
</VirtualHost>
for a digitalocean droplet given at the IP listed in the above hosts file. This droplet has absolutely nothing on it except for the wiki user in /home/ plus the required php, mysql/mariadb, apache stuff.
What I want to be able to do is to go to 159.203.171.140:8080 and see my site without having to purchase a useless domain name.
I'd really appreciate some help with this one.
If you have only one website on the droplet, then you don't need to set up a virtual host. You can use the 000-default.conf, no need for a2ensite.
You do not need the ServerName, which won't work with the IP as a name, you also don't need the IP address in the VirtualHost directive.
So, instead of this:
<VirtualHost 159.203.171.140:8080>
ServerAdmin webmaster#localhost
ServerName 159.203.171.140:8080
DocumentRoot "/home/wiki/public_html"
...
You can use this in your 000-default.conf file
<VirtualHost *:8080>
DocumentRoot "/home/wiki/public_html"
...
The rest of the directive stays as you have it.
Also, one note, if you are using port 8080, then you need go to /etc/apache2/ports.conf and set the Listen to 8080 (restart Apache after doing this).

Apache VirtualHost and localhost

I'm working with XAMPP on Mac OS X.
I'm trying to run a Symfony website properly for a client, and I really don't know Symfony (yet). I just want to install and launch it.
I've changed my /etc/hosts file this way:
127.0.0.1 www.mysite.local
And the httpd.conf file this way:
<VirtualHost *:80>
ServerName www.mysite.local
DocumentRoot /Applications/MAMP/htdocs/mysite/web
DirectoryIndex index.php
<Directory /Applications/MAMP/htdocs/mysite/web>
AllowOverride All
Allow from All
</Directory>
Alias /sf /Applications/MAMP/htdocs/mysite/lib/vendor/symfony/data/web/sf
<Directory "/Applications/MAMP/htdocs/mysite/lib/vendor/symfony/data/web/sf">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
Now, the site is working (yay!), but I can't access any more any of my other local sites because localhost is rendered as www.mysite.local.
Where am I wrong?
This worked for me!
To run projects like http://localhost/projectName:
<VirtualHost localhost:80>
ServerAdmin localhost
DocumentRoot path/to/htdocs/
ServerName localhost
</VirtualHost>
To run projects like http://somewebsite.com locally:
<VirtualHost somewebsite.com:80>
ServerAdmin webmaster#example.com
DocumentRoot /path/to/htdocs/somewebsiteFolder
ServerName www.somewebsite.com
ServerAlias somewebsite.com
</VirtualHost>
The same for other websites:
<VirtualHost anothersite.local:80>
ServerAdmin webmaster#example.com
DocumentRoot /path/to/htdocs/anotherSiteFolder
ServerName www.anothersite.local
ServerAlias anothersite.com
</VirtualHost>
localhost will always redirect to 127.0.0.1. You can trick this by naming your other VirtualHost to other local loop-back address, such as 127.0.0.2. Make sure you also change the corresponding hosts file to implement this.
For example, my httpd-vhosts.conf looks like this:
<VirtualHost 127.0.0.2:80>
DocumentRoot "D:/6. App Data/XAMPP Shared/htdocs/intranet"
ServerName intranet.dev
ServerAlias www.intranet.dev
ErrorLog "logs/intranet.dev-error.log"
CustomLog "logs/intranet.dec-access.log" combined
<Directory "D:/6. App Data/XAMPP Shared/htdocs/intranet">
Options Indexes FollowSymLinks ExecCGI Includes
Order allow,deny
Allow from all
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
(Notice that in <VirtualHost> section I typed 127.0.0.2:80. It means that this block of VirtualHost will only affects requests to IP address 127.0.0.2 port 80, which is the default port for HTTP.
To route the name intranet.dev properly, my hosts entry line is like this:
127.0.0.2 intranet.dev
This way, it will prevent you from creating another VirtualHost block for localhost, which is unnecessary.
This is normal if you see it. Since it is the first virtual host entry, it will show local host.
Let’s say for example you didn't want that page to show. All you want to show is the "Apache, it works" page, so you would make a vhost entry before mysite.local as local host and point it to the "it works" page.
But this is normal. I had this problem before, so don't worry!
You may want to use this:
<VirtualHost *:80>
DocumentRoot "somepath\Apache2.2\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
as your first virtual host (place it before other virtual hosts).
I had the same issue of accessing localhost while working with virtualHost. I resolved it by adding the name in the virtualHost listen code like below:
In my hosts file, I have added the below code (C:\Windows\System32\drivers\etc\hosts) -
127.0.0.1 main_live
And in my httpd.conf I have added the below code:
<VirtualHost main_live:80>
DocumentRoot H:/wamp/www/raj/main_live/
ServerName main_live
</VirtualHost>
That's it. It works, and I can use both localhost, phpmyadmin, as well as main_live (my virtual project) simultaneously.
Additional description for John Smith's answer from the official documentation. To understand why it is.
Main host goes away
If you are adding virtual hosts to an existing web server, you must
also create a block for the existing host. The
ServerName and DocumentRoot included in this virtual host should be
the same as the global ServerName and DocumentRoot. List this virtual
host first in the configuration file so that it will act as the
default host.
For example, to work properly with XAMPP, to prevent VirtualHost overriding the main host, add the follow lines into file httpd-vhosts.conf:
# Main host
<VirtualHost *:80>
ServerName localhost
DocumentRoot "/xampp/htdocs"
</VirtualHost>
# Additional host
<VirtualHost *:80>
# Over directives there
</VirtualHost>
For someone doing everything described here and still can't access:
XAMPP with Apache 2.4:
In file httpd-vhost.conf:
<VirtualHost *>
DocumentRoot "D:/xampp/htdocs/dir"
ServerName something.dev
<Directory "D:/xampp/htdocs/dir">
Require all granted #apache v 2.4.4 uses just this
</Directory>
</VirtualHost>
There isn't any need for a port, or an IP address here. Apache configures it on its own files. There isn't any need for NameVirtualHost *:80; it's deprecated. You can use it, but it doesn't make any difference.
Then to edit hosts, you must run Notepad as administrator (described below). If you were editing the file without doing this, you are editing a pseudo file, not the original (yes, it saves, etc., but it's not the real file)
In Windows:
Find the Notepad icon, right click, run as administrator, open file, go to C:/WINDOWS/system32/driver/etc/hosts, check "See all files", and open hosts.
If you were editing it before, probably you will see it's not the file you were previously editing when not running as administrator.
Then to check if Apache is reading your httpd-vhost.conf, go to folder xampFolder/apache/bin, Shift + right click, open a terminal command here, open XAMPP (as you usually do), start Apache, and then on the command line, type httpd -S. You will see a list of the virtual hosts. Just check if your something.dev is there.
According to this documentation: Name-based Virtual Host Support
You may be missing the following directive:
NameVirtualHost *:80
Just change <VirtualHost *:80> to <VirtualHost 127.0.0.1:80>.
Then the default DocumentRoot will serve for all domains or IP addresses that point to your server and specified VirtualHost will work.
It may be because your web folder (as mentioned "/Applications/MAMP/htdocs/mysite/web") is empty.
My suggestion is first to make your project and then work on making the virtual host.
I went with a similar situation. I was using an empty folder in the DocumentRoot in httpd-vhosts.confiz and I couldn't access my shahg101.com site.
I am running Ubuntu 16.04 (Xenial Xerus). This is what worked for me:
Open up a terminal and cd to /etc/apache2/sites-available. There
you will find a file called 000-default.conf.
Copy that file: cp 000-default.conf example.local.conf
Open that new file (I use Nano; use what you are comfortable with).
You will see a lot of commented lines, which you can delete.
Change <VirtualHost *:80> to <VirtualHost example.local:80>
Change the document root to reflect the location of your files.
Add the following line: ServerName example.local And if you need to, add this line: ServerAlias www.example.local
Save the file and restart Apache: service Apache2 restart
Open a browser and navigate to example.local. You should see your website.
For anyone using Windows and the Bitnami WAMP Stack Manager Tool this virtual host configuration should go into Bitnami\apache2\conf\bitnami\bitnami.conf
Note: Some settings in Directory section is not a must.
For example, my virtual host configuration for site.com would be as follows:
<VirtualHost site.com:80>
DocumentRoot "C:/Bitnami/apache2/htdocs/site/docroot"
<Directory "C:/Bitnami/apache2/htdocs/site/docroot">
Options Indexes FollowSymLinks
AllowOverride All
<IfVersion < 2.3 >
Order allow,deny
Allow from all
</IfVersion>
<IfVersion >= 2.3 >
Require all granted
</IfVersion>
</Directory>
</VirtualHost>
Remember that configuration for vhost as mentioned, by other friends, sagits's answer is needed.

Apache NameVirtuaHost does not respect ServerName's

I have an Apache server configured with several configuration files in which I declare VirtualHost's. However, when I access my server for one of the given ServerName it is not respected and defaults to another one.
My configurations is as followed:
In a ports.conf file I have this:
NameVirtualHost *:80
Listen 80
Then in another file, I have this:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName my.server.com
ServerAlias other.server.com
DocumentRoot /home/mys/
Alias / /home/mys/
ErrorLog /var/log/apache2/mys-error.log
<Directory /home/mys/>
Options Includes Indexes FollowSymLinks MultiViews
AllowOverride AuthConfig
Order allow,deny
allow from all
</Directory>
</VirtualHost>
In another file I have this
<VirtualHost *:80>
ServerName something.server.com
ServerAlias else.server.com
Redirect permanent / https://something.server.com
</VirtualHost>
And I have a configuration on port 443 for something.server.com which works ok
When I call http://my.server.com, I end up on https://something.server.com
All hostnames point to the same IP.
I am running on Apache/2.2.9 (Debian)
Any hint or ideas would be much appreciated. I am not an Apache expert so if I need to provide more info or formulate this in another way, just let me know.
OK, actually this is working fine, but because I indicated a Permanent Redirect, Firefox cached the redirect. So nothing wrong in the configuration (although one might say that is probably dangerous to indicate a permanent redirect).