Set up apache Virtual Host to serve static files - apache

I'm trying to set up a development environment for a javascript web application using apache, but I can't seem to do even the simplest of things, like setting up a virtual host to serve the static html, js, and other file types.
Here's what I'm trying to do in httpd-vhosts.conf:
<VirtualHost *:80>
ServerAdmin test#localhost
ServerName www.nonlocal-blight.com
ServerAlias www.local-blight.com
DocumentRoot "/Apache24/documents/WebContent"
<Directory "WebContent">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I've got an index.html file in WebContent, but whether I try to go to www.local-blight.com, or www.local-blight.com/index.html, I always get "Oops! Google Chrome could not find [whatever]". I've tried removing the ServerAlias, a different folders for the Document root, removing the line Options Indexes FollowSymLinks and everything.
I've tried using httpd.exe -S to check my virtual host configuration, but so far as I can see, the output looks good:
C:\Apache24\bin>httpd.exe -S
VirtualHost configuration:
*:80 is a NameVirtualHost
default server www.nonlocal-blight.com (C:/Apache24/conf/extra/httpd-vh
osts.conf:37)
port 80 namevhost www.nonlocal-blight.com (C:/Apache24/conf/extra/httpd
-vhosts.conf:37)
alias www.local-blight.com
port 80 namevhost www.nonlocal-blight.com (C:/Apache24/conf/extra/httpd
-vhosts.conf:37)
alias www.local-blight.com
*:443 is a NameVirtualHost
default server localhost (C:/Apache24/conf/extra/httpd-sni.conf:134)
port 443 namevhost localhost (C:/Apache24/conf/extra/httpd-sni.conf:134
)
port 443 namevhost localhost (C:/Apache24/conf/extra/httpd-sni.conf:134
)
port 443 namevhost serverone.tld (C:/Apache24/conf/extra/httpd-sni.conf
:151)
port 443 namevhost serverone.tld (C:/Apache24/conf/extra/httpd-sni.conf
:151)
port 443 namevhost servertwo.tld (C:/Apache24/conf/extra/httpd-sni.conf
:166)
port 443 namevhost servertwo.tld (C:/Apache24/conf/extra/httpd-sni.conf
:166)
ServerRoot: "C:/Apache24"
Main DocumentRoot: "C:/Apache24/documents"
Main ErrorLog: "C:/Apache24/logs/error.log"
Mutex ssl-stapling: using_defaults
Mutex proxy: using_defaults
Mutex ssl-cache: u
sing_defaults
Mutex default: dir="C:/Apache24/logs/" mechanism=default
PidFile: "C:/Apache24/logs/httpd.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
Define: SRVROOT=/Apache24
Can anyone tell me what I'm doing wrong here?

I needed to add the line:
127.0.0.1 www.local-blight.com
To my windows hosts file in %SystemRoot%\system32\drivers\etc\hosts.
I also needed to follow this answer to permit my system to access the files through a browser.

Related

Apache 2.4 installed on windows 11 and unable to get correct browser responses to requests for NamedVirtualHosts

I have Apache Lounge httpd-2.4.54-win64-VS17.zip installed on Windows 11.
I am following instructions at [1] to set up 2 vhosts. The vhosts are defined as:
# Ensure that Apache listens on port 80
#Listen *:80
<VirtualHost 192.168.0.1:80>
#/www/example1 directory is ralative to ${ServerRoot} which is "c:/apache24"
DocumentRoot "C:/Apache24/www/bletch"
ServerName bletch.net
ServerAlias www.bletch.net
</VirtualHost>
<VirtualHost 192.168.0.1:80>
DocumentRoot "C:/Apache24/www/dorfy"
ServerName dorfy.org
ServerAlias www.dorfy.org
</VirtualHost>
In httpd.conf, the Include conf/extra/httpd-vhosts.conf is uncommented.
The contents of /etc/hosts is:
127.0.0.0 localhost
::0 localhost
192.168.0.1 bletch.net
::1 bletch.net
192.168.0.1 dorfy.org
::1 dorfy.org
My httpd.conf contains the following:
Define SRVROOT "C:/Apache24"
ServerRoot "${SRVROOT}"
Listen 80
DocumentRoot "${SRVROOT}/htdocs"
<Directory "${SRVROOT}/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Include conf/extra/httpd-vhosts.conf
I have a unique index.html file in the htdocs, bletch, and dorfy directories so I will know exactly which one, if any, is being displayed in browser when requested. And I am using two browsers for testing, google chrome and ms edge.
I have cleared browser cache, set browswer to recognize and use /etc/hosts for local DNS lookup, and have run ipconfig /flushdns, and restarted httpd.
I have executed httpd -t -D DUMP_VHOSTS -D DUMP_RUN_CFG and got the following report:
C:\Apache24\bin>httpd -t -D DUMP_VHOSTS -D DUMP_RUN_CFG
VirtualHost configuration:
192.168.0.1:80 is a NameVirtualHost
default server bletch.net (C:/Apache24/conf/extra/httpd-vhosts.conf:44)
port 80 namevhost bletch.net (C:/Apache24/conf/extra/httpd-vhosts.conf:44)
alias www.bletch.net
port 80 namevhost dorfy.org (C:/Apache24/conf/extra/httpd-vhosts.conf:51)
alias www.dorfy.org
ServerRoot: "C:/Apache24"
Main DocumentRoot: "C:/Apache24/htdocs"
Main ErrorLog: "C:/Apache24/logs/error.log"
Mutex default: dir="C:/Apache24/logs/" mechanism=default
PidFile: "C:/Apache24/logs/httpd.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
Define: SRVROOT=C:/Apache24
THE PROBLEM IS:
Request for localhost works correctly in both browers.
Request for www.bletch.net and www.dorfy.org in both browsers reslults in site can't be reached.
Request for bletch.net and dorfy.org both result in display of locoalhost index.html.
I have reviewed multiple posts on StackOverFlow, and Apache users list archive and found solutions to various problems (such as the need to set browsers to use /etc/hosts DNS lookup file and other mistakes I made) but have not found what is needed at the current state explained here.
Please, can anyone tell me what how to fix this? Thanks.
[1] [Troubleshooting Vhosts][1]

Ubuntu Apache Using Wrong VHosts For Sites

I'm using Ubuntu 16.0.4, and have vhost configured, with all .conf files located at /etc/apache2/sites-available and all enabled sites at /etc/apache2/sites-enabled using a2ensite for each site conf. I have 000-default.conf disabled, and I'm using certbot, along with the latest of apache and PHP 7.2.x.
Two of my sites have an issue with the vhost configuration. The sites are:
Site 1: clients.site1.com.conf
Site 2: clients.site2.com.conf
Site 3: site3.com.conf (Mention later)
If I go to clients.site1.com in the browser, it loads fine.
If I go to clients.site2.com in the browser, the url shows clients.site2.com loaded, but it is actually loading clients.site1.com content from /var/www/clients.site1.com/public_html.
I've checked clients.site1.com.conf, and have the following:
<VirtualHost *:80>
ServerAdmin webmaster#clients.site1.com
ServerName clients.site1.com
ServerAlias clients.site1.com
DocumentRoot /var/www/clients.site1.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =clients.site1.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
I've checked clients.site2.com.conf, and have the following:
<VirtualHost *:80>
ServerAdmin webmaster#clients.site2.com
ServerName clients.site2.com
ServerAlias clients.site2.com
DocumentRoot /var/www/clients.site2.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =clients.site2.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
I have played around with the file name of the conf files thinking that having two conf files with clients. had an issue with the wildcard matching. So I tried removing the dot ., and even tried replacing it with a hyphen -. Still the same result.
The last test I did was I disabled clients.site1.com.conf. When I did that and then proceeded with loading clients.site2.com in my browser, the next site in order of the conf files (Site 3 above to serve as an example) is what loads.
UPDATE:
I ran apache2ctl -S and got the following:
root#ip-111-111-111-111:/etc/apache2/sites-available# apache2ctl -S
VirtualHost configuration:
*:443 is a NameVirtualHost
default server clients.site1.com (/etc/apache2/sites-enabled/clients.site1.com-le-ssl.conf:2)
port 443 namevhost clients.site1.com (/etc/apache2/sites-enabled/clients.site1.com-le-ssl.conf:2)
alias clients.site1.com
port 443 namevhost site3.com (/etc/apache2/sites-enabled/site3.com-le-ssl.conf:2)
alias www.site3.com
port 443 namevhost aaaaa.com (/etc/apache2/sites-enabled/aaaaa.com-le-ssl.conf:2)
alias www.aaaaa.com
port 443 namevhost bbbbb.com (/etc/apache2/sites-enabled/bbbbb.com-le-ssl.conf:2)
alias www.bbbbb.com
port 443 namevhost ccccc.com (/etc/apache2/sites-enabled/ccccc.com-le-ssl.conf:2)
alias www.ccccc.com
port 443 namevhost ddddd.com (/etc/apache2/sites-enabled/ddddd.com-le-ssl.conf:2)
alias www.ddddd.com
port 443 namevhost eeeee.com (/etc/apache2/sites-enabled/eeeee.com-le-ssl.conf:2)
alias www.eeeee.com
port 443 namevhost ip-111-111-111-111.ec2.internal (/etc/apache2/sites-enabled/fffff.com-le-ssl.conf:2)
alias www.fffff.com
port 443 namevhost ggggg.com (/etc/apache2/sites-enabled/ggggg.com-le-ssl.conf:2)
alias www.ggggg.com
port 443 namevhost site2.com (/etc/apache2/sites-enabled/site2.com-le-ssl.conf:2)
alias www.site2.com
*:80 is a NameVirtualHost
default server ip-111-111-111-111.ec2.internal (/etc/apache2/sites-enabled/000-default.conf:1)
port 80 namevhost ip-111-111-111-111.ec2.internal (/etc/apache2/sites-enabled/000-default.conf:1)
port 80 namevhost clients.site1.com (/etc/apache2/sites-enabled/clients.site1.com.conf:1)
alias clients.site1.com
port 80 namevhost clients.site2.com (/etc/apache2/sites-enabled/clients.site2.com.conf:1)
alias clients.site2.com
port 80 namevhost site3.com (/etc/apache2/sites-enabled/site3.com.conf:1)
alias www.site3.com
port 80 namevhost aaaaa.com (/etc/apache2/sites-enabled/aaaaa.com.conf:1)
alias www.aaaaa.com
port 80 namevhost bbbbb.com (/etc/apache2/sites-enabled/bbbbb.com.conf:1)
alias www.bbbbb.com
port 80 namevhost ccccc.com (/etc/apache2/sites-enabled/ccccc.com.conf:1)
alias www.ccccc.com
port 80 namevhost ddddd.com (/etc/apache2/sites-enabled/ddddd.com.conf:1)
alias www.ddddd.com
port 80 namevhost eeeee.com (/etc/apache2/sites-enabled/eeeee.com.conf:1)
alias www.eeeee.com
port 80 namevhost ip-111-111-111-111.ec2.internal (/etc/apache2/sites-enabled/fffff.com.conf:1)
alias www.fffff.com
port 80 namevhost ggggg.com (/etc/apache2/sites-enabled/ggggg.com.conf:1)
alias www.ggggg.com
port 80 namevhost site2.com (/etc/apache2/sites-enabled/site2.com.conf:1)
alias www.site2.com
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex ssl-stapling: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: using_defaults
Mutex ssl-stapling-refresh: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33
root#ip-111-111-111-111:/etc/apache2/sites-available#
There are a couple of things you can do to help with debugging:
apache2ctl -S
This will show you the vhost configuration that Apache believes you have. it is important to a2dissite a configuration file before renaming it, etc.
I have 000-default.conf disabled
You are better off keeping this enabled and creating a default file that is loaded when Apache doesn't know where to go. It can be a very simple file that just says "error", but then you will be aware when Apache believes it has nowhere to go. Plus it is better security to have a honey pot for all requests coming in that aren't legitimate. Lastly, I have this vague memory of discovering that it might actually pick one of the vhosts randomly if the 000-default is not set, but not sure, but it would explain the site 3 behavior.
Lastly, you have both ServerName and ServerAlias set to the same URL. This is not necessary and while I don't think it is the problem, better to take it out of the mix.
Otherwise I do not see any problems with your vhosts files and should work.
Update
You are redirecting to the https URL. So what is dictating Apache is the -le-ssl.com.conf file. I have similarly fought this with Let's Encrypt. Here are my procedures for making both Apache and Let's Encrypt happy:
create the one configuration (website.com.conf) for the non-secure port 80
a2ensite website.com.conf
apache2ctl graceful (so Apache knows of the non-secure URL)
letsencrypt --apache -d website.com (this will generate the entire -le-ssl file)
apache2ctl graceful
In case it can help somebody : I had the exact same problem.
Several websites configured in Apache. They were working correctly.
I moved them to a new server. I don't know why (maybe a difference in the default Apache conf) but they started to behave like explained in the question, like "pointing" to a default site.
The reason was that I didn't have a ServerAlias line forwarding the "non www" name of the site to the "www prefixed" name.
I was used to typing "mydomainname.com" instead of "www.mydomainname.com" because I have a line in my DNS config that forwards the requests to www.xxxx if www is missing.
So, Apache was not finding the ServerName, and trying to pass the request to the default site.
But, because I has deleted the content of the 000-default.conf file, the request was passed to the first working website.
So make sure you have :
A working 000-default.conf file
A ServerAlias for your www prefixed site like
ServerAlias www.yourdomainname.com

www.Example.com works but not root (Example.com)

I am using Apache2 with UBUNTU14 LTS, all "standard" server.
The problem is simple, when using http://www.example.com it works fine, but when using http://example.com it doesn't, it goes to the wrong index.
Describing details
I have folders at ls /var/www/
example.com example2.example html
wiki.example.com wp.example2.example
Each with different and good index.htm working with http://www.example.com (goes to /var/www/example.com) or http://wiki.example.com, etc. But the index of http://example.com goes to /var/www/html/index.htm, not to /var/www/example.com (!).
At /etc/apache2/sites-available/example.com.conf we have,
<VirtualHost *:80>
ServerAdmin mymail#ggmail.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName wiki.example.com
DocumentRoot /var/www/wiki.example.com
</VirtualHost>
EDIT (notes)
We are using a workaround — and please ignore the "real world" examples in the comments, it is not valid as real testing —, an ugly piece of PHP code (not a solution) in the /var/www/html/index.php of the root (no subdomain), to redirect to www subdomain,
if ( preg_match( // if HTTP from other domain, redirects
'/(mydomain1|mydomain2|mydomain3)/',
strtolower($_SERVER['HTTP_HOST']),
$m
) ) switch($m[1]) {
case 'mydomain1':
header("Location: https://www.example.com"); die('');
case 'mydomain2':
header("Location: https://www.example2.example"); die('');
case '...':
header("Location: https://www...."); die('');
}
EDIT
As #covener comment suggest, apachectl -S, results in
VirtualHost configuration:
*:80 is a NameVirtualHost
default server localhost (/etc/apache2/sites-enabled/000-default.conf:1)
port 80 namevhost localhost (/etc/apache2/sites-enabled/000-default.conf:1)
port 80 namevhost atarica.com.br (/etc/apache2/sites-enabled/atarica.com.br.conf:1)
alias www.atarica.com.br
port 80 namevhost wiki.atarica.com.br (/etc/apache2/sites-enabled/atarica.com.br.conf:13)
port 80 namevhost atarica.com.br (/etc/apache2/sites-enabled/fabrincantes.com.conf:1)
alias www.fabrincantes.com
port 80 namevhost yellowtown.org (/etc/apache2/sites-enabled/yellowtown.org.conf:1)
alias www.yellowtown.org
port 80 namevhost wiki.yellowtown.org (/etc/apache2/sites-enabled/yellowtown.org.conf:35)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33 not_used
Group: name="www-data" id=33 not_used
Try this:
<VirtualHost *:80>
ServerName example.com
Redirect permanent / http://www.example.com/
</VirtualHost>
Then you just need to create another section with ServerName www.example.com for your real server configuration.
Also, wouldn't CNAME's records work has an alternative to this? (I'm not sure)
Sorry all, that was my "human error", as blind spot when reading file.conf scripts, and a general blindness here after my edit showing apachectl -S results, the error is there (! see fabrincantes.com lines), a wrong name "AAA" on the "BBB" configuration:
port 80 namevhost AAA (/etc/apache2/sites-enabled/BBB.conf:1)
alias BBB
so I fixed with simple name correction on my BBB.conf, that has an ServerName AAA instead "BBB",
<VirtualHost *:80>
...
ServerName BBB
...
</VirtualHost>
You would require to edit your /etc/hosts file so it points to correct links.
For example, configuration on my localhost would be
127.0.1.1 example.com www.example.com

Why doesn't this Apache virtualhost entry work?

I'm running Apache 2.4.6 on Ubuntu 13.
In sites-available, I have a conf file for my site that contains only this:
<VirtualHost *:80>
# Admin email, Server Name (domain name), and any aliases
ServerAdmin somebody#somewhere.com
ServerName www.ourco.me
ServerAlias ourco.me
# Index file and Document Root (where the public files are located)
DirectoryIndex index.html index.php
DocumentRoot /home/ouruser/public/ourco.me/public
# Log file locations
LogLevel warn
ErrorLog /home/ouruser/public/ourco.me/log/error.log
CustomLog /home/ouruser/public/ourco.me/log/access.log combined
</VirtualHost>
There are no other conf files enabled. When I have use apachectl -S to display the sites, it shows:
VirtualHost configuration:
*:80 is a NameVirtualHost
default server www.ourco.me (/etc/apache2/sites-enabled/ourco.me.conf:1)
port 80 namevhost www.ourco.me (/etc/apache2/sites-enabled/ourco.me.conf:1)
alias ourco.me
port 80 namevhost www.ourco.me (/etc/apache2/sites-enabled/ourco.me.conf:1)
alias ourco.me
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex watchdog-callback: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
Mutex mpm-accept: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33
The first thing I notice is the duplicate entry for namevhost www.ourco.me. And when I visit the site in a browser, I get:
You don't have permission to access / on this server.
Apache/2.4.6 (Ubuntu) Server at www.ourco.me Port 80
All the directories and files specified in the conf file exist. a2ensite and a2dissite work as expected to add/remove a symlink for this file from sites-enabled, so it's looking at the right file. Does anyone know why its directives are being ignored? Thanks.
Put Allow from all
<VirtualHost *:80>
# Admin email, Server Name (domain name), and any aliases
ServerAdmin somebody#somewhere.com
ServerName www.ourco.me
ServerAlias ourco.me
# Index file and Document Root (where the public files are located)
DirectoryIndex index.html index.php
DocumentRoot /home/ouruser/public/ourco.me/public
# Log file locations
LogLevel warn
ErrorLog /home/ouruser/public/ourco.me/log/error.log
CustomLog /home/ouruser/public/ourco.me/log/access.log combined
Allow from all
</VirtualHost>
This appears to solve the problem:
<Directory />
Require all granted
</Directory>
when placed in the VirtualHost entry.
That snippet came from this post. I'm looking at this Apache doc to see why it works.

Multiple Virtual Hosts on Different Ports in WAMP

So I have this problem...
I use WAMP and have set up perfectly working Virtual Hosts in the past, but now I have come to something I never foresaw.
I am trying to do this:
Access C:\wamp\www through http://localhost
Access D:\somethingelse through http://localhost:8080 OR http://something.dev
I much prefer using the proper http://something.dev, as the working site is http://something.co, and so I can keep them separate.
I have followed guides and read forum posts, but all I have manages to do so far is this:
Access C:\wamp\www through http://localhost OR http://something.dev
Access D:\somethingelse through http://localhost:8080 OR http://something.dev:8080
Anybody got any idea how you would do this? Here's my VirtualHost Code:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot "C:\wamp\www"
ServerName localhost
ServerAlias www.localhost.com
ErrorLog "logs/localhost-error.log"
CustomLog "logs/localhost-access.log" common
</VirtualHost>
<VirtualHost *:8080>
ServerAdmin webmaster#something
DocumentRoot "D:/something/www"
ServerName something.dev
ServerAlias www.something.dev
ErrorLog "logs/something-error.log"
CustomLog "logs/something-access.log" common
<directory "D:/something/www">
Options Indexes FollowSymLinks
AllowOverride all
Order Allow,Deny
Allow from all
</directory>
</VirtualHost>
And in httpd.conf I have this
Listen *:80
Listen *:8080
And my hosts file is working and points both of these to 127.0.0.1
(The reason I want to do this is that when I code on my machine I use the http://something.dev, but I run Livereload Windows, and test my website simultaneously on an iPhone and iPad on the same local network, but without any access to iOS's equivalent of the hosts file. It also allows me to open up only a specific part of my server to the internet, through port forwarding on my router.)
I suppose you have solved the issue. Anyway is good to share some nice information on how to set up multiple Virtual Hosts in Wamp. This is working for me:
http://www.kristengrote.com/blog/articles/how-to-set-up-virtual-hosts-using-wamp
In my case I am working with ports 8080 and 8181. 8080 is redirecting to a subfolder under c:\wamp\www\myfolder, while 8181 is redirecting to root c:\wamp\www.
To make 8181 work I had to edit httpd-vhosts.conf, hosts (in \drivers\etc folder) and httpd.conf.
In httpd.conf my Apache is listening:
Listen 8080
Listen 8181
also I uncommented:
Include conf/extra/httpd-vhosts.conf
my root is pointing to
DocumentRoot "c:/wamp/www/myfolder"
root directory is configured as:
<Directory "c:/wamp/www">
Options Indexes FollowSymLinks
AllowOverride All
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
Allow from ::1
Allow from localhost
</Directory>
and added:
<VirtualHost *:8181>
DocumentRoot "C:\wamp\www"
ServerName name-of-my-fake-server
</VirtualHost>
in httpd-vhosts.conf I have set:
NameVirtualHost *:8181
in hosts (c:\windows\system32\drivers\etc) I have added:
127.0.0.1 localhost
127.0.0.1 name-of-my-fake-server #My Test Site
Doing that I have now two ports working 8080 and 8181: so 8080 points to directory "c:\wamp\www\myfolder" and the other port 8181 points to my root folder "c:\wamp\www\"
Using * as the hostname requires the use of NameVirtualHost:
NameVirtualHost *:80
NameVirtualHost *:8080
For those with MAMP, edit the httpd.conf
nano /Applications/MAMP/conf/apache/httpd.conf
Add Listen for each port
Listen 80
Listen 8080
And the ServerName too
ServerName localhost:80
ServerName localhost:8080
Once done that, edit httpd-vhosts.conf
nano /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
Define NameVirtualHost
NameVirtualHost *:80
NameVirtualHost *:8080
And the VirtualHost's
<VirtualHost *:80>
DocumentRoot "/Users/yourUser/path/project1"
ServerName project1.local
</VirtualHost>
<VirtualHost *:8080>
DocumentRoot "/Users/yourUser/path/project2"
ServerName project2.local
</VirtualHost>
Of course you need to have project1.local and project2.local in your hosts file
sudo nano /etc/hosts
And add
127.0.0.1 project1.local project2.local
Restart MAMP and you could access your vhost by
project1.local
project2.local:8080
project2 could be access also in your network or with a external IP (e.g to test from a different device like a mobile phone). Assuming your IP is 192.168.1.10
192.168.1.10:8080
The question is a little about it. But I assumed that it's near there and may be helpful for somebody.
Recently I met the problem when I need to get access to a few resources (debian repository, my website and phpmyadmin) by one external IP address and port.
After learning the problem I found technology named as reverse proxy. It like proxy but server is accepting all connection from many users and redirect to one target (your server).
I made simple Docker image and docker-compose file and push that to github.com/urpylka/docker-nginx-reverse-proxy and hub.docker.com.
Config file is very simple:
server {
listen 80;
server_name smirart.ru robotic.lol;
location / {
proxy_pass http://robotic.lol:1080/;
}
}
server {
listen 80;
server_name repo.smirart.ru;
location / {
proxy_pass http://8.8.8.8:2080/;
}
}
You can use that for few web-servers running by different IP.