Apache httpd.conf VirtualHost: Attach to the same IP but different port (non standard) - apache

I have a webserver with 2 domains (already attached to a folder), I want my global server configuration, which basically using "/var/www/html" as default document root, to have ANOTHER folder for ANOTHER user, based on just different port (I have read that it is possible in Apache site).
Follow is the cite from apache site:
Each Virtual Host must correspond to a different IP address, different port number, or a different host name for the server, in the former case the server machine must be configured to accept IP packets for multiple addresses. (If the machine does not have multiple network interfaces, then this can be accomplished with the ifconfig alias command -- if your OS supports it).
So my IP is XX.XX.XX.XX and server configuration has the line "listen 443" (I am running by default on https), I did the following:
listen 19758 https
<VirtualHost XX.XX.XX.XX:19785>
ServerName XX.XX.XX.XX:19785
DocumentRoot "/the/path/to/the/user/directory/public_html"
<Directory "/the/path/to/the/user/directory/public_html">
AllowOverride none
Options SymLinksIfOwnerMatch
Require all granted
</Directory>
<IfModule mpm_itk.c>
AssignUserID EFX EFX
</IfModule>
</VirtualHost>
I opened the port in the iptables, and made sure it is opened.
However: When I open the browser and typing "XX.XX.XX.XX:19785", it just timeouts without giving me the page (index.htm) that sits in the desired directory.
Note: This user has no associated domain, and will never has one.
The server is running with 2 other domains that have associated folders, I don't want to mix with them.
What I am doing wrong?
The main idea is to be able to enter from the browser to that directory as that user, and not as "nobody" (the default user of the server in the configuration file).
Thanks a lot for help.

Related

WAMP Server cannot be accessed through local network [duplicate]

So I set up a few virtual hosts with unique urls and they work just fine on the desktop. However, when I connect a mobile device on the network, it can't seem to access anything properly but the default localhost virtualhost and that's only when it's the only virtualhost I have up.
My setup and coding is pretty much this except with a different site title
wamp server 3.0 virtual host on another device
and while that solution redirects me to my unique url, it has a lack of images on a default wordpress website.
Has anyone managed to get mobile devices fully accessing links other than on localhost?
Since I posted the answer you referenced, I have decided upon a simpler solution.
What the actual problem is
Because we cannot fiddle with the configuration of a phone like we can with a PC, the phone can never find the domain name we create in our Virtual Host definition on the Server machine, because it does not exist in any DNS Server for it to locate the IP Address in, and a DNS Server is the only place a phone can look, unless it is jail broke.
If you wanted to access one of your Virtual Hosts domains from another PC you could just add a line like this into the HOSTS file on the other PC like this.
192.168.0.10 example.local
But you cannot do that on a phone/tablet.
What Apache expects to be able to asssociate a request to a Vhost
When we create an Apache Virtual Host, we are actually telling Apache to look at the domain name on the incoming connection and match that domain name to a ServerName that exists in one of our multiple Virtual Hosts definitions.
But if we use for example example.local as our virtually hosted domain when we attempt to connect to that from our phone, the phone does a DNS Lookup and does not find that domain and therefore cannot get its ip address.
The simplest way to get round this is:
Assuming we do not have access to adding record to a DNS Server we have to come up with a different solution.
The simplest of these is to use the IP Address of the PC running the WAMPServer(Apache) server and a specific port number. So thats a different port number for each of our sites we want to use from a phone.
So how do we do this
Add the new listening port to httpd.conf like so after the 2 existing Listen statements
WAMPServer 3: Do this using the menus, not by doing a manual edit on httpd.conf
right click wampmanager-> Tools -> Add listen port for Apache
#Listen 12.34.56.78:80
Listen 0.0.0.0:80
Listen [::0]:80
Listen 0.0.0.0:8000
Listen [::0]:8000
Suggested httpd-vhosts.conf file
#
# Virtual Hosts
#
# Always keep localhost, and always first in the list
# this way a ramdom look at your IP address from an external IP
# maybe a hack, will get told access denied
<VirtualHost *:80>
ServerName localhost
DocumentRoot c:/wamp/www
<Directory "c:/wamp/www/">
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
# The normal Vhost definition for one of our sites
<VirtualHost *:80>
ServerName example.local
DocumentRoot "c:/websrc/example/www"
<Directory "d:/websrc/example/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
# Access example.dev from phone for testing
<VirtualHost *:8000>
ServerName example.local
DocumentRoot "c:/websrc/example/www"
<Directory "d:/websrc/example/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
# assuming yoursubnet is 192.168.0.?
# allow any ip on your WIFI access
Require ip 192.168.0
</Directory>
</VirtualHost>
Restart Apache from wampmanager after completing these edits.
Now you test this from the WAMPServer PC by using the ServerName i.e example.dev and from the phone using the ip of the PC running WAMPServer with the port number i.e. 192.168.0.10:8000
Apache will find the correct code to serve from both requests.
If you want more than one Virtual Host to be accessible from your phone you just duplicate this idea and change the port number for each new site, lets say you would use 8001,8002,8003 etc. For as many sites as you want to access.
You may also have to amend your firewall to allow access on http on port 8000, or whatever port you pick to use

Accessing local host from another machine

I have seen many answers on this with what would appear to be simple solutions, none of which are working for me at this time.
I have WAMP install with Apache 2.4.33 32bit installed on a PC. I can access the site on that PC without a problem using the alias mySite.local.
The PC's host file looks like this
127.0.0.1 mySite.local
The remote lap top's host file is
192.168.1.114 mySite.local
That is the IP of the PC on the network.
httpd.conf
Listen 80
ServerName mySite.local:80
<Directory />
AllowOverride none
Require all denied
</Directory>
DocumentRoot "H:/Intranet/mySite_v2_www/public"
httpd-vhosts.conf
<VirtualHost *:80>
ServerName mySite.local
DocumentRoot "H:/Intranet/mySite_v2_www/public"
</VirtualHost>
I have tried disabling the windows firewall and virus checker on the PC.
The laptop appears to be getting there but being blocked. The message is..
Forbidden
You don't have permission to access / on this server.
Apache/2.4.33 (Win32) PHP/7.2.4 Server at mySite.local Port 80
So it looks like it can see Apache but is being blocked. So what else needs to be set to get access to the server?
Here are two of the links that I have been following to try and get this to work
Error message "Forbidden You don't have permission to access / on this server"
and
How do I connect to this localhost from another computer on the same network?
Thanks for any direction you can provide.
To complement the answer of Paul Neale:
Forbidden You don't have permission to access / on this server. Apache/2.4.33 (Win32) PHP/7.2.4 Server at mySite.local Port 80
That message is an answer from Apache. Disabling the windows firewall and virus checker on the PC won't have any effect, you are already reaching Apache there is not any networking problem.
Apache is receiving your request to access the root folder "public":
H:/Intranet/mySite_v2_www/public
But denies the request because, the directive Require local is enabled. This directive means, you can access to the content of public from the local server (localhost), which is the same to say 127.0.0.0 or localhost.
What you wanted is to tell apache that allows the access of certain IP address to the root directory "public".
When you changed the directive to Require all granted you are telling apache that, no matter who asks, give it access to / (root folder) in other words "public".
So, what you was searching for is "Access Control" in apache, and the directive Require can be used with IP address, here's the main document from Apache, this is an example:
Require host address
Require ip ip.address
It's important to differentiate between Network//Permissions problems. If you want to know if you are able to communicate (At network level) with Apache, you could do:
telnet <IP_APACHE_SERVER> <PORT_APACHE_SERVER>
#example: telnet 172.10.10.2 80
So after playing around will combinations for a day I found that in the httpd.conf I needed to change Require local to Require all granted in the section.
<Directory "H:/Intranet/mySite_v2_www/public/">
Options +Indexes +FollowSymLinks +Multiviews
AllowOverride all
# onlineoffline tag - don't remove
# Require local
Require all granted
</Directory>

Laravel Access forbidden on localhost xampp

I just got stuck in the very begining. I have installed laravel and when i run php artisan serv command then this(Laravel development server started on http://localhost:8000/) line appears but when i access it through browser(http://localhost:8000/) then the following error gets displayed.
Access forbidden!
You don't have permission to access the requested object. It is either read-protected or not readable by the server.
If you think this is a server error, please contact the webmaster.
Error 403
localhost
Apache/2.4.18 (Win32) OpenSSL/1.0.2e PHP/7.0.2
Please help me out. Any help would be greatly appreciated. I am beginner in laravel.
Follow the steps below to create a virtual host:
Change to your XAMPP installation directory (typically, C:\xampp) and open the " httpd-vhosts.conf " and " httpd-xampp.conf " files in the apache\conf\extra\ subdirectory using your favourite text editor.
Add these lines into both files with the following directives:
<VirtualHost *:80>
DocumentRoot "C:\Users\Shivam\Desktop\laravel_project\blog"
ServerName blog.dev
<Directory "C:\Users\Shivam\Desktop\laravel_project\blog">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Deny,Allow
Allow from all
Require all granted
</Directory>
</VirtualHost>
This contains two virtual host configuration blocks:
The first block is the default or fallback virtual host, which is used for all requests that are not matched by subsequent blocks.
The second block sets up a virtual host named wordpress.localhost. The DocumentRoot directive specifies the directory to be used when serving requests for this virtual host (in this case, the WordPress installation directory), while the ServerName directive specifies the custom domain name for the virtual host.
To add more virtual hosts, simply duplicate the second virtual host block and modify the port number, DocumentRoot and ServerName directives as per your requirements. For example, if you want to use SSL with your custom domain name, you can add a new virtual host block for port 443.
If you plan to have a large number of virtual hosts with very similar configuration, consider using wildcard-based subdomains with your virtual hosts.
Restart Apache using the XAMPP control panel for your changes to take effect.
At this point, your virtual host is configured. However, if you try browsing to the wordpress.localhost domain, your browser will show a failure notice, since this domain does not exist in reality. To resolve this, it is necessary to map the custom domain to the local IP address. To do this, open the file C:\windows\system32\drivers\etc\hosts and add the following line to it:
127.0.0.1 blog.dev
This takes care of mapping the wordpress.localhost domain name to the local machine, which always has the IP address 127.0.0.1
It seems to me that you already have Apache running on port 8000.
Try running the serve command like this:
php artisan serve --port=9000
After it's running navigate to http://localhost:9000

Can't access apache from Internet

It must be a common question but I've not found any appropriate answer:
I have a website on apache server running in my office LAN. I can view pages from all computers (even smart-phones via Wifi).
All computers are connected to a router (with static IPs) which supports port forwarding.
I forwarded the routers port 8080 to the internal IP 192.168.1.5:80 which is the apache box (xubuntu 14.04).
The problem is that when I try to view the site from the internet, I always get connection refused response. I tried the http://www.canyouseeme.org but still the response is the same. This happens both when I try from my LAN->Internet->Router->Apache or directly from home Internet->Router->Apache.
I know (rather suspect) that the routed does its job because if I hit the external static IP:80 I get into its interface while when I hit IP:8080 I get the connection refused response. Canyouseeme agrees (it times out as it's waiting for a password).
Funny(?) thing is that I have not installed a firewall and the apache2.conf is the default.
Can somebody help?
Finally it is all clear; my ISP didn't allow to set the routers firewall so every setting I made was void.
So to recap first make sure that your ISP is really forwarding your ports.
However I couldn't up my site (zoneminder app) so I write down the solution in case someone else finds it useful:
First of all I assume that Apache is running without problems with the default settings. In case that you want to make a site (in your system you'll see directory) available as the root site of your apache serer, you must create a "rule" for apache:
First copy the 000-default.conf file that lies in /etc/apache2/sites-available/ directory (in Ubuntu systems) by executing
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/mysite.conf
The mysite.conf file will be a setting for virtual host and you will need to add/change contents accordingly with:
DocumentRoot /my/site/directory
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /my/site/directory/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
Don't forget to change (if needed) the port apache is listening to by editing the /etc/apache2/ports.conf.

XAMPP Apache site-root-relative links work locally, fail when accessing dev site via remote machine over LAN

Am trying to set up multiple site development areas on a single server machine, then work on content from other computers over LAN. (Excuse the general wording of my questions, the site keeps preventing me from entering example URLs, etc.)
When I work directly on the server machine, entering
my-virtual-host-name:port#
as the URL everything works beautifully. It correctly resolves all links, image references, etc, as being relative to the site root.
When I connect from a different machine, over our Lan, entering
server-ip-address:port#
I get automatically redirected to a default XAMPP welcome page (So I am at least connecting to the server)
I figured how to setup an Alias statement, so that, for example something like
server-computer-ip-address:port#/alias-for-file-path
gets me to the home page for my site. But subsequently when I click on links, for example
/products-services
which I would want to go to
server-ip-address/alias-for-file-path/products-services
it instead resolves to
server-ip-address/products-services
Relevant settings on the computer running the Apache server
IP Address: 192.168.22.12
In Windows Host file: 127.0.0.1 localhost mySiteName
In httpd-vhosts.conf:
NameVirtualHost *
<VirtualHost *>
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *>
DocumentRoot "D:\companysites\newproducts\mysite"
ServerName mySiteName
<Directory "D:\companysites\newproducts\mysite">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
In httpd.conf (assigning alternate port to Apache, since 80 is otherwise used):
Listen 3399
Have tried a bunch of things not detailed here, trying to figure out how to correctly define some combination of server machine and remote machine virtual host definitions and url settings, as well as much web searching and zero luck so far!
At present you've set it up so all Virtual Hosts are listening for the same connection. Same ip from all ports. *
I figured it out, finally! Hopefully this will be useful and clear to someone else! (I am new to this, so may be obvious to others - there were some basic things I didn't understand and now do...)
In httpd-vhosts.conf file, you can:
Create any number of "Listen" statements, each with a unique port number. So, for example.
Listen 8885
Listen 8886
Listen 8887
Then you can create any number of VirtualHost definition sections, associating one of the above ports with each, for example:
NameVirtualHost *
<VirtualHost 192.168.22.11:3399>
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost 192.168.22.11:3388>
DocumentRoot "file-system/path"
ServerName mySiteName
<Directory "file-system/path">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
When connecting to the server from a remote computer, it is not possible to use any combination of alias server names and/or alias file path names (at least, didn't work for me - if there is a way, I'd be interested to know). Instead, always enter ip-address:port#, for example, enter, as the URL to one of the defined sub-domains on the server machine:
192.168.22.11:3399