I'm working on an Ubuntu 12.04 server with Apache and I'm trying to setup 2 virtual host. The problem is I don't know how to setup the .conf files correctly so that I can hit both virtual host correctly from a remote machine...
For example if the Ubuntu sever has an address of 192.168.1.3, and I'm using another machine, how can I access each virtual host with http://192.168.1.3/host1 and http://192.168.1.3/host2?
right now in my /etc/apache2/sites-available folder I have the following 2 files
host1.conf
<VirtualHost *:80>
ServerName 192.168.1.3/host1
ServerAlias host1
DocumentRoot /var/www/host1/
.....
host2.conf
<VirtualHost *:80>
ServerName 192.168.1.3/host2
ServerAlias host2
DocumentRoot /var/www/host2/
.....
what is the correct configuration to make the virtual host work correctly when accessing from a remote machine?
The simplest way to achieve this is to assign host names to both your virtual hosts. E.g: host1.local.com & host2.local.com. Then in your remote machine, open /etc/hosts (you will require sudo privileges) and add the following lines:
192.168.1.3 host1.local.com
192.168.1.3 host2.local.com
Your virtual hosts config would be:
<VirtualHost *:80>
ServerName host1.local.com
Related
Created a new Laravel project in htdocs in MAMP. Followed all the steps, added virtual hosts, changed conf file, etc/hosts, restarted mamp and my pc several times but I just can't get my virtual host to run.
however, when I am in the MAMP Dashboard I can navigate to my website -> website -> public and the default Laravel boilerplate page appears.
Has anyone had this issues with MAMP before? I gave up with XAMPP and Valet so it's my last chance here..
Specs
High Sierra 10.13.5 on 2015 MBP,
Composer version 1.6.5,
php 7.2.7
httpd.conf
# Virtual hosts
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
httpd-vhosts
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /Applications/MAMP/htdocs
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "Applications/MAMP/htdocs/website/public"
ServerName website.dev
</VirtualHost>
etc/hosts
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
#255.255.255.255 broadcasthost
#::1 localhost
127.0.0.1 website.dev
website.dev is technically a public url, so the browser is looking for it on the internet I guess. I was trapped once in this dreadful situation. changing the name to something like website.local should solve your issue. It did for me.
I wanted to host one website in local Network.(it is not accessed by out side the network)
i install apache server.
how can i create own domain name for that(i don't want buy any domain name).
it is my virtual host file
ServerName testing.com
ServerAlias www.testing.com
DocumentRoot /var/www/testing.com/public_html
It works only when i put localhost as serverName
locahost file
127.0.0.1 somedomain.com
I am trying to create a virtual host in apache2 running on VirtualBox guest OS is Ubuntu 14.04 LTS. The following is the configuration of my virtualhost in /etc/apache2/sites-available/mysite.lo.conf
<VirtualHost *:80>
Servername mysite.lo
ServerAlias www.mysite.lo
DocumentRoot /var/www/mysite.lo
</VirtualHost>
Settings in /etc/hosts
127.0.0.1 localhost
172.16.17.146 mysite.lo
When i try to run www.mysite.lo from my host browser, the browser responds no resuts found. When I type the ip address 172.16.17.146 then the browser successfully displays the content of mysite.lo. I would be grateful if someone can guide me on how to access the contents using the servername instead of ip adress. This is the link I have used as a guide to create my virtual host. Regards.
you should add www.mysite.lo to 172.16.17.146 line, or run mysite.lo without www. from host browser.
I am setting a virtual host with wamp server following this tutorial
http://www.kristengrote.com/blog/articles/how-to-set-up-virtual-hosts-using-wamp
hosts file
127.0.0.1 localhost
127.0.0.1 dev.gamenomad.com
httpd-vhosts.conf
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "C:\wamp\www\dev.gamenomad.com\public"
ServerName dev.gamenomad.com
ServerAlias dev.gamenomad.com
ErrorLog "logs/dev.gamenomad.com-error.log"
CustomLog "logs/dev.gamenomad.com-access.log" common
</VirtualHost>
<Directory C:\wamp\www>
Order Deny,Allow
Allow from all
</Directory>
httpd.conf
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
I am unable to access dev.gamenomad.com . I got this error
i18n-values: Missing value for "primaryParagraph"
GET http://dev.gamenomad.com/ net::ERR_CONNECTION_REFUSED http://dev.gamenomad.com/:1
fyi, my apache server listen to port 8080 instead of the default 80. Does it affect my virtual host?
For wamp, you can set a virtual host using swamp UI as well. For that, you need to left-click on wamp icon -> Your Virtual hosts -> VirtualHost Management.
Then, just enter the server name, absolute path to the folder and then create the virtual host.
You can check it yourself here
Use gamenomad.git instead dev.gamenomad.com
And directory like Document root and goto c:\windows\system32\drivers\etc
Open the "hosts" file
And goto end line and type
127.0.0.1 gamenomad.git
Save change as administrator
End
I am currently trying to configure the Virtual Host (Subdomain) of my Apache HTTP Server so it can be accessed with another computer on my LAN. The current setup of Apache with PHP and MySQL works locally on the same physical machine.
So I have two Virtual Host setup (development and cms) running on a non-default port of 50080. The machine of the server have a IP of 10.0.0.10. From the same physical machine, I can access the two Virtual Host using:
development.localhost:50080
cms.localhost:50080
From a different physical machine, I can access the root of the server using:
10.0.0.10:50080
But I cannot or do not know how to access the Virtual Host from the different machine. I tried something like:
development.10.0.0.10:50080
cms.10.0.0.10:50080
But they do not seem to work.
Here's how my httpd-vhosts file looks like:
NameVirtualHost *:50080
<VirtualHost *:50080>
DocumentRoot "C:/www/HTTP"
ServerName localhost
</VirtualHost>
<VirtualHost *:50080>
ServerAdmin administrator#development.localhost
DocumentRoot "C:/www/HTTP/development"
ServerName development.localhost
ErrorLog "logs/development.localhost-error.log"
CustomLog "logs/development.localhost-access.log" common
</VirtualHost>
I read some of the other post here and the Apache forum, but there's not exact case for this.
I was wondering how I can access the Virtual Host (Subdomain) from another machine and keep the same port if possible.
Thanks in advance
Ok, I figured it out, here are the configuration if anyone else is looking for this:
==================================================================================
Machine A (Apache HTTP Server):
httpd-vhost:
NameVirtualHost *:50080
<VirtualHost *:50080>
DocumentRoot "C:/www/HTTP"
ServerName localhost
ServerAlias alias <!-- Added -->
</VirtualHost>
<VirtualHost *:50080>
ServerAdmin administrator#development.localhost
DocumentRoot "C:/www/HTTP/development"
ServerName development.localhost
ServerAlias development.phoenix <!-- Added -->
ErrorLog "logs/development.localhost-error.log"
CustomLog "logs/development.localhost-access.log" common
</VirtualHost>
hosts:
127.0.0.1 development.localhost
127.0.0.1 alias
127.0.0.1 development.alias
==================================================================================
Machine B (Guest Machine):
hosts:
10.0.0.10 alias
10.0.0.10 development.alias
From the second machine, you should be able to access with "alias" and "development.alias"
I suggest making the following change (add the ServerAlias lines):
NameVirtualHost *:50080
<VirtualHost *:50080>
DocumentRoot "C:/www/HTTP"
ServerName localhost
ServerAlias cms.myserver.com
</VirtualHost>
<VirtualHost *:50080>
ServerAdmin administrator#development.localhost
DocumentRoot "C:/www/HTTP/development"
ServerName development.localhost
ServerAlias development.myserver.com
ErrorLog "logs/development.localhost-error.log"
CustomLog "logs/development.localhost-access.log" common
</VirtualHost>
Restart Apache to ensure the changes take effect.
Then on your second computer you need to add a custom dns entry for these new domain names. If it is Windows, edit the file c:\windows\system32\drivers\etc\hosts. If it is Linux, edit /etc/hosts. Either way add:
10.0.0.10 development.myserver.com
10.0.0.10 cms.myserver.com
Now on your second computer you should be able to access the following URLs:
http://development.myserver.com:50080
http://cms.myserver.com:50080
Unless I'm missing something, you'll need to either set up DNS entries, or add entries to the /etc/hosts file of each computer accessing the server.
localhost is an entry that exists in everyone's /etc/hosts file by default, always pointing to 127.0.0.1. Without adding a /etc/hosts entry, developer.localhost doesn't exist, and prefixing an ip address with a subdomain won't work at all.
Using a SSH + Putty tunnel, and thus having a 127.0.0.1 on my server, I managed to access my subdomains by doing the following on my server side:
# nano /etc/hosts
127.0.0.1 localhost.localdomain localhost
127.0.0.1 sub1.domain.com sub2.domain.com sub3.domain.com sub4.domain.com
I did not change the host file of the remote computer, and it works like a charm
For Named Virtual Hosts you need to use a hostname or domainname to connect to you apache server. It does not work with ips.
You could insert an entry in your /etc/hosts on your second system.