Apache - Configuring multiple websites accessed by same IP but different ports - linux

I have done this in IIS7.5 with ease.
Say I have a domain mbdev.myftp.biz.
On IIS I have setup sites but each one has a different port.
Example:
mbdev.myftp.biz:8004
mbdev.myftp.biz:8006
The only thing that is different is the port for the site. Those above URL's got to actual sites on the IIS box.
How can I accomplish the same thing with APACHE? Having the site be on a specific port?
For Example:
mbdev.myftp.biz:8600
mbdev.myftp.biz:8601

Apache accomplishes this through the VirtualHost directive. Documentation for version 2.4 can be found on http://httpd.apache.org/docs/2.4/vhosts/index.html and more specifically the configuration directive http://httpd.apache.org/docs/2.4/mod/core.html#virtualhost
An example virtualhost config directive pulled from the link above:
<VirtualHost 10.1.2.3:80>
ServerAdmin webmaster#host.example.com
DocumentRoot /www/docs/host.example.com
ServerName host.example.com
ErrorLog logs/host.example.com-error_log
TransferLog logs/host.example.com-access_log
</VirtualHost>

Related

Apache Virtual Host isn't Serving Virtual Host 'index.html' at Domain Name

When I go to my ip address an index file is served.
However when I navigate to my domain name a page isn't served.
Apache won't serve content from my (domain name) web directory.
I don't plan to install PHP or a Database until the virtual hosts implementation is legit.
I've reinstalled my image more times than I can count to get my websites migrated to a virtual server. The biggest sticking point is configuring the virtual hosts. My latest attempt was using this blog article:
https://www.tecmint.com/install-apache-with-virtual-hosts-on-debian-10/
Before that it was this article in previous attempts:
https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mariadb-php-lamp-stack-on-debian-10
I looked at this article too:
https://linuxize.com/post/how-to-set-up-apache-virtual-hosts-on-debian-10/
I saw mentions of a user called www-data during my internet search but it isn't mentioned in the three blog posts I cited.
My hosting company keeps telling me to use Plesk but they didn't configure the shared hosting environment for the migration extension.
So I can't use Plesk to migrate and they charge me a monthly fee for the Plesk license if it is installed on the image.
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
ServerAdmin webmaster#example.com
DocumentRoot /var/www/html/example.com
<Directory /var/www/html/example.com>
Options -Indexes +FollowSymLinks
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined
/etc/apache2/sites-available/example.com.conf
I looked at the domain name in other browsers and Chrome is forcing HTTPS at my request. I didn't get around to reinstalling the SSL/TLS because of the confusion with the virtual hosts. So basically the page has been live the entire time but Chrome wouldn't connect because a secure connection was unavailable.
This probably is not the correct answer, but I went into my file /etc/apache2/sites-enabled/000-default.conf
and changed the lines from:
#<VirtualHost *:80>
<VirtualHost *:8888>
#DocumentRoot /var/www/html
DocumentRoot /home/MyPath/Drives/02000/www

Change name of local web service

I setup a local guacamole server for people in my work to access several VM's that we have running in the server. IN order to access guacamole the have to type http://ip:port/guacamole or after the host override I did in my pfsense DNS resolver http://guac.loc:port/guacamole. The problem is that even that some times is problematic for some of them so I want to do something like http://guac.loc so they can remember it easily. I did it for some with the hosta file but I can't different functionallities for some of them. So can anyone help on how to do that? Can I do it somehow from the web server? Or do I need to setup a DNS Server?
If I understand correctly, you want to have "simpler" URL, without port and "guacamole" path.
Guacamole by default runs under Tomcat on port 8080. However, you can put Apache in front of the Tomcat and proxy request to the guacamole. Apache can proxy and forward all requests to the Guacamole on the given port and path.
Something like the example below should work and also will redirect all http requests to the htpts. It is not mandatory to have SSL enabled, you can proxy http as well.
<VirtualHost *:80>
ServerName guac.loc
Redirect permanent / https://guac.loc/
</VirtualHost>
<VirtualHost *:443>
ServerName guac.loc
SSLEngine on
SSLCertificateFile /etc/ssl/certs/guac-loc.cer
SSLCertificateKeyFile /etc/ssl/private/guac-loc.key
SSLCACertificateFile /etc/ssl/certs/guac-loc-ca.crt
<Location /guacamole/>
ProxyPass http://localhost:8080/guacamole/ flushpackets=on
ProxyPassReverse http://localhost:8080/guacamole/
Order allow,deny
Allow from all
</Location>
</VirtualHost>

VirtualHost not redirecting

I am trying to redirect http://eamondev.com:3000 to https://omniatm.eamondev.com with a VirtualHost. I am using node to serve a site to http://eamondev.com:3000. I am using vhost with node like this:
app.use(vhost('omniatm.eamondev.com', express.static('/')));
I have never used vhost and it took me a while to figure this out without having to split up all my code like I was working with more than one site (when I am not), so I'm not sure if it is exactly how it should be for an Apache redirect to work.
In my apache conf file I have:
<VirtualHost *:80>
ServerName omniatm.eamondev.com
ProxyPreserveHost on
ProxyPass / http://localhost:3000/
</VirtualHost>
I am also using WHM on a VPS, I'm not sure if this is relevant or not, but the ServerName (with protocol, what I type into the browser) needs to be https://omniatm.eamondev.com.
I cannot serve node on port 80 of my server (and then redirect to subdomain) because my main site (http://eamondev.com) is running on port 80.
I have referenced most of the stackoverflow questions about this and nothing has worked. I should mention (although I'm not sure exactly how it is relevant, I just saw it in a stackoverflow question I looked at), my hosting support (bluehost) used WHM to set things up with a wildcard ssl certificate to make the omniatm.eamondev.com subdomain https.
How do I redirect http://eamondev.com:3000 to https://omniatm.eamondev.com using apache (or vhost)?
Proxy passing as given in the question will not do any redirects instead it will retain the URL as such and proxy the content from elsewhere. In Apache configuration, we have an option to do redirects, in the bellow sample, we are checking for the host and based on it issuing an redirect to the desired URL
<VirtualHost *:80>
ServerName omniatm.eamondev.com
Redirect / https://omniatm.eamondev.com
<If "%{HTTP_HOST} != 'eamondev.com:3000'">
Redirect "^/?(.*)" "https://omniatm.eamondev.com/$1"
</If>
</VirtualHost>

How to access to site by 2 address

I have a site now with address https://example.com/. How to make possible access to this site also by address https://example.com.html? What to write in htaccess?
What to write in htaccess?
Nothing special.
The question is not what to write but what to not write in .htaccess. And the answer is: do not write anything that links the site to one of its names (example.com or example.com.html). The same applies to the PHP source or configuration files.
The rest is just proper names registration, nameserver and Apache configuration.
Regarding the configuration of Apache, let's say the IP address of your web server is 1.2.3.4. The Apache configuration file (httpd.conf f.e.) now contains something similar to this:
<VirtualHost 1.2.3.4:80>
ServerName example.com
DocumentRoot "/www/docs/example.com"
# Other configuration directives for domain example.com
</VirtualHost>
In order to let Apache know the domain example.com.html is the same as example.com you can add a ServerAlias to the <VirtualHost> block:
<VirtualHost 1.2.3.4:80>
ServerName example.com
ServerAlias example.com.html
DocumentRoot "/www/docs/example.com"
# Other configuration directives for domain example.com
</VirtualHost>
Assuming you already have the name and the name servers are properly configured to point to your existing server, restart Apache and it should work.
Read more about <VirtualHost> and ServerAlias

Apache virtual hosts - server ip directing to virtual host instead of /var/www/html

I have set up a linux box mainly for testing and I have got to a stage were apache, mysql and php are running. I followed tutorials on how to set up virtual hosts so I can point domains to it but something strange is happening.
This is my httpd-vhosts.conf file that I have included in my httpd.conf file:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName thedomain.co.uk
DocumentRoot /var/www/thedomain
</VirtualHost>
When I go to thedomain.co.uk it is pointing to the correct place as you'd expect. But when I go to my servers ip, internal or external it is going to the same directory as the virtual host. Could you guys think of any reason that is? I would expect it to go to /var/www/html by default? Oh and I'm running CentOS 6.3
Thanks in advance for any answers!
You have used wildcard to point everything at DocumentRoot /var/www/thedomain
You need to create second listing :
<VirtualHost myotherdomain.co.uk:80>
ServerName myotherdomain.co.uk
DocumentRoot /var/www/myotherdomain
</VirtualHost>
where your other domain is whatver ip and the document root, points to your choise.
The first vhost listing is also used as the default ... so if you were to use localhost it would resolve to whatever is first in list.

Resources