How can I create different ports on Apache VirtualHosts - apache

I'm trying to create VirtualHost for a different port number with below code, but when I try to access that port number "domain: port" I receive "ERR_CONNECTION_REFUSED" error on browser.
Steps, what I do
First editing http.conf, created for the related domain via Plesk
I am writing these codes
Restart Apache
Also I add that port number on httpd.conf. (Listen: port) but at this point I receive "Internal Server Error"
What do I use:
Plesk 12,
Apache/2.2.15 (Unix),
Ngnix (Reserve proxy)
<VirtualHost IP:8324>
DocumentRoot "/var/www/vhosts/httpdocs"
ServerName "domain:8324"
ServerAlias "www.domain.com"
ServerAlias "ipv4.domain.com"
UseCanonicalName Off
<Directory /var/www/vhosts/httpdocs>
DirectoryIndex index.php
Options +Indexes +FollowSymLinks +MultiViews +Includes
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
What am I missing? Thank you

I think you can do that using a custom template for a specific vhost.
You should check these two links. The might put you on the right track:
https://docs.plesk.com/en-US/12.5/advanced-administration-guide-linux/virtual-hosts-configuration/changing-virtual-hosts-settings-using-configuration-templates/example-changing-default-apache-ports.68800/
https://docs.plesk.com/en-US/onyx/advanced-administration-guide-linux/virtual-hosts-configuration/changing-virtual-hosts-settings-using-configuration-templates.68693/
Just so you know, any manual changes that you do in the httpd.conf file (from a ssh console for example, at the next plesk update or when you add/delete an account, they will be overwritten since Plesk is regenerating the httpd.conf file)

Related

This site can’t be reached - XAMPP ignores custom domain vhosts

Environment
XAMPP 7.2.4 installed on Windows 10
Apache running on ports 80 and 443
Configuration
C:\Windows\System32\drivers\etc\hosts:
127.0.0.1 www.test.local test.local
C:\xampp\apache\conf\httpd.conf:
DocumentRoot "D:/htdocs"
<Directory "D:/htdocs">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
C:\xampp\apache\conf\extra\httpd-vhosts.conf:
<VirtualHost *:80>
DocumentRoot D:/htdocs
ServerName localhost
<Directory "D:/htdocs">
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot D:/htdocs
ServerName test.local
<Directory "D:/htdocs">
Allow from all
</Directory>
</VirtualHost>
The problem
When I start Apache and I access to localhost is all right. The problem comes when I try to reach test.local: the browser returns a This site can’t be reached message. It's like XAMPP ignores the custom domain vhosts defined into httpd-vhost.conf file. The same message is displayed with the server off.
This site can’t be reached
The webpage at http://test.local/ might be temporarily down or it may have moved permanently to a new web address.
ERR_ADDRESS_INVALID
A few days ago the setup was working and the only changes that I made was the new software installation. I mean, no changes in Apache config files.
If all your stack were working correctly before, don't be like me and don't forget to check if some browser extension is blocking your local traffic, like some extension related with an antivirus system.
In my case it was the Kaspersky Protection extension. When something goes wrong, it shows the following graphic.
C:\Windows\System32\drivers\etc
127.0.0.1 test.local
C:\xampp\apache\conf\extra\httpd-vhosts.conf:
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "C:/wamp64/www/test"
ServerName test.local
<Directory "C:/wamp64/www/hydroboost/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
Have you updated your C:\Windows\System32\drivers\etc\hosts file with a mapping like this this?
add this line to the end of the hosts file
127.0.0.1 test.local
the localhost domain works without this mapping, because the OS already recognizes "localhost" as a built in alias for the loopback IP address
(this suggestion is assuming that you are running and testing on the same local machine)

virtual host access from another computer

I am working in a php project using wamp. I have these wamp installed in my public server, so till now when I hit 204.XXX.XX.XX/projectname I could access from any computer inside my university. Now I dont want to display this localhost main screen so I tried virtual host configuration.
C:\Windows\System32\drivers\etc\hosts file
I added
204.XXX.XX.XX api.local #api
httpd-vhosts.conf
<VirtualHost *:80>
ServerName api.local
ServerAlias api.local
DocumentRoot "c:/wamp64/www/api"
<Directory "c:/wamp64/www/api/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
I have already enabled the virtual host.
Now from other computer I could not access this api.local project. How can I fix this issue?
THe reason is that the other computer does not know where to find api.local. The browser will look for that domain name in the DNS Server that is registered to be used on the OTHER PC and obviously not find it.
So the other PC needs to know the ip address to go to when you enter api.local. You can do this in a number of ways.
If your Uni techs will allow you to add this domain name to their DNS Server this is the best way.
But if they wont allow this, then you will have to edit the HOSTS file on the OTHER PC like this
204.xxx.xxx.xxx api.local
Now this one PC will know where to find your site. However the HOSTS file is normally well protected and you would need Administrator access to change it, which you admins may not allow.
Another way would be to make the site available on a different port, then you can use the WAMPServer PC ip address and a port number to get to your site like this
Listen 8000
<VirtualHost *:8000>
ServerName api.local
ServerAlias api.local
DocumentRoot "c:/wamp64/www/api"
<Directory "c:/wamp64/www/api/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Now use 204.xxx.xxx.xxx:8000 as the site address and you should get to your site

VirtualHost in Apache 2.4 replaces DocumentRoot when using http://localhost

I'm using Yosemite with Apache 2.4
/private/etc/apache2/httpd.conf
ServerName 127.0.0.1:80
DocumentRoot "/Library/WebServer/Documents/"
<Directory "/Library/WebServer/Documents">
Options Multiviews FollowSymLinks
MultiviewsMatch Any
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Everything is fine, http://localhost directs me to the default /Library/WebServer/Documents/index.html
After adding Include /private/etc/apache2/extra/httpd-vhosts.conf to /private/etc/apache2/httpd.conf
And adding the config below to /private/etc/apache2/extra/httpd-vhosts.conf
<VirtualHost *:80>
ServerAdmin admin#xxx.com
ServerName xxx.local
DocumentRoot "/Library/WebServer/Documents/xxx"
<Directory "/Library/WebServer/Documents/xxx/">
Options +FollowSymLinks
AllowOverride all
Require all granted
</Directory>
</VirtualHost>
When using http://localhost and http://127.0.0.1 from the browser, Apache directs me to /Library/WebServer/Documents/xxx/index.html instead of /Library/WebServer/Documents/index.html, how can I fix it?, please guide.
Thanks.
I had the same problem today.
I found solution here: httpd.apache.org/docs/current/vhosts/name-based.html.
Main host goes away
Any request that doesn't match an existing is handled by the global server configuration, regardless of the hostname or ServerName.
When you add a name-based virtual host to an existing server, and the virtual host arguments match preexisting IP and port combinations, requests will now be handled by an explicit virtual host. In this case, it's usually wise to create a default virtual host with a ServerName matching that of the base server. New domains on the same interface and port, but requiring separate configurations, can then be added as subsequent (non-default) virtual hosts.

Apache Port Redirection

I have some trouble concerning Apache Webserver 2.4.7. I want to redirect some pages to another port (doesn't matter which one, I choose 82). Therefore, I edited the VirtualHosts as follows:
<VirtualHost _default_:82>
DocumentRoot /var/www/html/hpc_test/web/trunk/
ServerName localhost
<Directory /var/www/html/hpc_test/web/trunk/>
Options Indexes FollowSymLinks MultiViews Includes
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
The redirection works fine but the new DocumentRoot does not. Some SSI commands are used assuming that /var/www/html/hpc_test/web/trunk/ is the DocRoot. Unfortunately, /var/www/html/ is considered as DocRoot for port 82.
Does any Apache expert can tell me if there's anything else I have to do? I studied the documentation and followed those instructions.
Cheers
First check if apache correctly listen in the port 82 :
netstat -laputen|grep 82
In your web-browser, do you use http://localhost:82 ?
Because you just listen to ServerName localhost, if you try with an other domain, apache going to redirecting in your default vHost

Virtual host & DNS on apacheserver

I was given a DNS-named called xxxx.hosterspace.com to my trial VPS-server located at 111.111.111.111. However, I am having some trouble having that DNS-name as default when I try to enter the server.
Whenever I enter xxxx.hosterspace.com, I end up at 111.111.111.111. I don't know how to fix this, I would like to keep xxxx.hosterspace.com in the addressfield.
This is my apache2.conf
<VirtualHost *:80>
ServerName xxxx.hosterspace.com
DocumentRoot /var/www/mediawiki/
<Directory /var/www/mediawiki>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
This is my sites-enabled/000-default
<VirtualHost *:80>
ServerName xxxx.hosterspace.com
DocumentRoot /var/www/mediawiki/
<Directory /var/www/mediawiki>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
Anyone who knows how to set this up? Don't really get any errors when I try to launch it. I have runned sudo service apache2 restart
Looking at the Apache configuration file(s) you've posted, I don't see how the redirect could be happening at the Apache level. It looks like you're running MediaWiki, so you may want to look at its configuration file(s) and ensure that MediaWiki isn't causing the redirect to the IP address.