Config VirtualHosts on Debian/Apache - apache

On my debian/apache server at http://localhost I'm redirected to my api on port 3000 (this is ok)
Now I would like to open another port (8090), in http://localhost:8090 redirected to /var/www/html/
How to make?

Find the default virtual host conf file by running
ls /etc/apache2/sites-available/
There should be a file called deault.conf, or similar. We want to edit this file
sudo nano /etc/apache2/sites-available/default.conf
Make sure that apache actually is listening to your port 8090 by adding, to the top of that document
Listen 8090
Change the rest of the conf file to match your site, so it may look something like this
Listen 8090
<VirtualHost *:8090>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/
# Other directives here
</VirtualHost>
Save the file with a different name in the same folder. The files must end with ".conf". Add the virtual host to enabled sites by running
sudo a2ensite virtual_host_file_name.conf
replacing "virtual_host_file_name.conf" with the name of the file you select in the previous step.
Then restart the apache server
sudo service apache2 reload
It seems like you're only interested in accessing it from localhost, but if you want to access it remotely you might need to check your firewalls.

Related

Managing multiple sites on XAMPP

I have multiple sites deployed on xampp. For now, all of the sites are using one port i.e. 80. For this reason, whenever I am logged into one of the sites, I am automatically logged out from the other and vice versa. I have looked at this article to How to run multiple websites on XAMPP on Windows. And tried to follow it but I am unable to do the needful.
I have added one more port to listen
Listen 80
Listen 8080
In my httpd-vhosts.conf I have done the following
NameVirtualHost *:8080
<VirtualHost *:8000>
DocumentRoot "F:\xampp\htdocs\mdc"
ServerName localhost:8080
<\VirtualHost>
After doing this I have turned off my xampp and then tried to restart apache and mysql. But apache is not starting
My URL is http://localhost:8080/mdc/backend/web
Note: Without doing any virtual host setting the above URL is accessible on both 80 and 8080 ports
Update 1
Herer is my httpd.conf file
This is not a fix for your issue, Here i will explain how i manage multiple websites on xampp.
First i assumes that your using windows
i always use the same port with different server names.
on : E:\xampp\apache\conf\extra\httpd-vhosts.conf (In my case i installed xampp on E drive)
i added this code
<VirtualHost *:80>
DocumentRoot "e:/xampp/htdocs/mysite1"
ServerName mysite1.flames.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "e:/xampp/htdocs/mysite2"
ServerName mysite2.flames-team.com
</VirtualHost>
And on ( C:\Windows\System32\drivers\etc\hosts) my windows host file i added this lines
127.0.0.1 mysite1.flames.com
127.0.0.1 mysite2.flames-team.com
With this approach you can access the site with a clean readable URLs
In this case if you want to see the first site just enter this URL mysite1.flames.com on browser.
Cheers
Write the closing tag </VirtualHost> instead of <\VirtualHost> in the file httpd-vhosts.conf. I did it and it worked for me.

configuration of domainname in httpd.conf and /etc/hosts

I am facing an issue with configuring domain name in my httpd.conf file. Entry in httpd.conf file.
Listen sample.com:443
<VirtualHost sample.com:443>
SSLEnable
ServerName MyIHSInstalledServerName
</VirtualHost>
KeyFile /serverPath/keyfile.kdb
SSLDisable
SSLTrace
Now I am confused on what should be the entry made in /etc/hosts
{IP} sample.com sample. Here what is the IP I should mention and is my entry in httpd.conf file correct? Please help.
Your /etc/hosts file is not really relevant to your Apache config.
For SSL virtual hosts, use either the actual ip address that you want your SSL httpd daemon to be bound to
eg
<VirtualHost 10.1.1.1:443>
or use:
<VirtualHost _default_:443>
which will bind the daemon to the first ip address not in use by any other SSL virtual host, which should work in the vast majority of cases
The name of the service is only relevant to the ServerName directive. If you include that, the httpd daemon will only respond to requests that include that name in the header.

Connection to localhost fails

I set up /etc/apache2/extra/httpd-vhosts.conf as follows:
# Ensure that Apache listens on port 80
Listen 80
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
<VirtualHost *:80>
ServerName localhost
DocumentRoot /Library/WebServer/Documents/
</VirtualHost>
In /Library/WebServer/Documents/ is the standard index.html.en file which was shown perfectly in the browser before I included the httpd-vhosts.conf into my httpd.conf.
The connection to localhost fails using both, Chrome and Firefox. Is the setup correct? What else could go wrong?
I solved the problem. I couldn't state further information because I just didn't know where I could look for the problem. This post put me in the right way:
http://macosx.com/forums/mac-os-x-system-mac-software/299851-apache-wont-start-up.html
sudo apachectl configtest
Gave me an syntax error within the httpd.conf file. After fixing it everything worked. The important thing is the opportunity to run a configtest.

XAMPP (WIN7) port change and vhosts

I've decided to change the ports for Apache to clear up some conflicts with other applications, and maybe even give IIS a shot in the future. I've run into the problem described below.
The basic context:
WIN 7 x64
XAMPP 1.7.4 (Apache 2.2.17, MySQL 5.5.8, PHP 5.3.5)
So I've changed the default Apache port from 80 to 8080, by changing this in the httpd.conf:
Listen 8080 (was Listen 80)
ServerName localhost:8080 (was ServerName localhost)
In my vhosts file I have:
NameVirtualHost 127.0.0.1:8080
And several virtual hosts defined like this:
<VirtualHost 127.0.0.1:8080>
DocumentRoot "somepath"
ServerName servername
<directory "somepath">
usual stuff here
</directory>
</VirtualHost>
When I try to access the virtual host using the servername defined above it does not work without explicitly specifying the port:
servername:8080
It would also seem that the port defined in the vhosts file does not make any difference, whatever I tried (80, 8080, nothing), it allways requires the port to be given with the server name.
phpinfo() says:
SERVER_PORT: 8080
Apache error logs do not show any errors.
I guess I'm wondering if this is normal behaviour, or there is something I overlooked.
The 80 port is default for browsers so that's why you don't need to access servername:80. In your case it's normal to acces server like this : servername:8080
If your want to access localhost without specify the port number in the URL http://localhost instead of http://localhost:8080.
Open Xampp Control Panel
Go to Config ► Service and Port Settings ► Apache
Replace the Main Port value ​​with 8080.
Save Service settings
Save Configuration of Control Panel
Restart the Apache Server

Multiple Apache2 vhosts are pointing to the same website

I'm running Apache2 on Ubuntu 10, and I have my site configuration files laid out numerically and in order. My default server is psychedeli.ca, but I also run another site off the same box at mahoganytales.com. Currently, both of these domains point to the same site (the one for psychedeli.ca). The declaration NameVirtualHost *:80 is in my ports.conf file, so I'm pretty sure my global server config checks out. How can I fix this?
Here are my vhost files:
001-psycho
<VirtualHost *:80>
DocumentRoot /var/apps/psycho/public
ServerName psychedeli.ca
</VirtualHost>
002-mahogany
<VirtualHost *:80>
DocumentRoot /var/apps/mahogany/public
ServerName mahoganytales.com
</VirtualHost>
try create new conf file at /etc/apache2/conf.d, e.g., vhosts.conf
with this content in it:
NameVirtualHost *
It looks like the default configuration is in effect rather than your host entries. Following is the procedure that works in Ubuntu Apache2.
First,
create a VirtualHost in /etc/apache2/sites-available/somesite,
then a2ensite somesite to make it live.
Finally, /etc/init.d/apache2 restart to restart apache.
If you think, you have followed the above steps, then can you please confirm, that you have your hosts files in /etc/apache2/sites-enabled/?
Each domain name needs to have it's own single unique ip address, that's how different sites are found.
By using the *:80 in the virtual host directive, you're instructing Apache to listen on all IP addresses, port 80 and send it to this directory. With your second vhost, you're doing the same thing (All IP's port 80, and send it there). Well, since you're giving it two conflicting statements, it takes the first match, and uses it.
If you want to serve multiple websites, each must answer to it's own unique IP address, ie:
site aaa.com - 145.25.82.110
site bbb.com - 145.25.82.111
From there, each vhost entry will listen on it's own ip address and port for each site. In the OP's case the vhost needs to change to (using the example IPs):
&ltVirtualHost 145.25.82.110:80>
DocumentRoot /var/apps/psycho/public
ServerName psychedeli.ca
&lt/VirtualHost>
&ltVirtualHost 145.25.82.111:80>
DocumentRoot /var/apps/mahogany/public
ServerName mahoganytales.com
&lt/VirtualHost>
This instructs the server to listen on static IP 1 port 80 (as defined in the named.conf and associtated bind config files, and send it to the first site base directory, and any calls on the second static IP port 80 and send it to the second site base directory.
As for configuring bind/named, that's beyond the scope of this question...