Create Virtualhost on port 81

Asked

Viewed 2,249 times

6

I have two apaches installed for two versions of PHP (5 and 7), on port 80 and 81 respectively.

I would like to create virtualhost for apache port 81

In the host file there is this line:

Host

127.0.0.1        projeto.dev
127.0.0.1        localhost81

I created a file called project81.conf inside a folder called alias

project81.conf

NameVirtualHost *:81
<VirtualHost *:81> 
  DocumentRoot C:/www81/projeto/public
  ServerName projeto.dev
  <Directory "C:/www81/projeto/public">
        Require all granted
    </Directory>
</VirtualHost> 

Inside the httpd.conf file I added the line:

httpd.conf

# Alias

Include conf/alias/*.conf

I restarted the service, but it doesn’t work.

What I have to do more?

To the localhost81:81 works

From there I would like to make this vhost available on the local network

  • Are you in linux environment? Using some xampp or installed apache and PHP natively?

  • PHP and Apache separate

  • In Windows environment

4 answers

2

In this case you use the proxys, apache keeps getting the requests on port 80, and then it forwards to another host and port, so you don’t need to define directories in this type of vhost, apache just re-lists the request. would look something like this:

<VirtualHost *:80> 
  ProxyPreserveHost On
  ProxyRequests Off
  ServerName localhost81
  ServerAlias localhost81
  ProxyPass / http://localhost:81/
  ProxyPassReverse / http://localhost:81/
</VirtualHost>

In the hosts file, you continue with the alias localhost81. I hope I’ve helped.

  • remembering that mod_proxy must be enabled in your apache.

  • This setting gave error in my apache

  • which error message?

  • apache does not start

  • Can you see the logs? made sure to enable mod_proxy in apache?

  • I just enabled mod_proxy

  • Now gave Internal Server Error

  • Does it have something to do with the dns of the local network?

  • If you’re running everything on your machine can’t be dns local, do you have access to apache logs? For more accurate information.

Show 4 more comments

2

When I set up other ports in apache, I usually put the following instruction together with Virtualhost:

Listen 81
Listen 8080

<VirtualHost *:81>
    ServerName localhost
    DocumentRoot "/www/domain-81"
</VirtualHost>

<VirtualHost *:8080>
    ServerName localhost
    DocumentRoot "/www/domain-8080"
</VirtualHost>
  • But I already have port 80 localhost and if I wanted to access port 81 type localhost81 would only change the servername?

  • I put localhost in the example because I point several hosts to the localhost in different folders. This works if vc put in Windows hosts files. In your case, I think you missed the point for the apache to listen to port 81: Listen 81

  • You can put multiple folders to run on apache port 80. <VirtualHost *:80>&#xA; ServerName host1&#xA; DocumentRoot "/sua/pasta"&#xA;</VirtualHost> You can create multiple Virtualhost with the same Servername (localhost), and change only the folder. Hence vc adds this line in Windows hosts files (c: windows system32 drivers etc): 127.0.0.1 host1&#xA;127.0.0.1 host2

  • But wouldn’t that be for multiple hosts on the same server? From what I understand, it has 2 apaches, with two different versions of PHP in each of them, so I think the best is that the apache of port 80 points to the apache of port 81 on a given host, no?

  • Actually a better and more practical solution for (local) development environment, is to use Ocker, then you raise a php 7 environment or php 5 environment, whenever you need it, here are some examples: https://github.com/luizpaulofranz/docker-environments

1

This setup is simple, first step and put apache to listen on the port you want, the second step and configure vhost to point the port to a directory you want loaded when prompted, after that and only give a Reload or Restart service.

First step

In some OS you will find this option in httpd.conf, if it is in Debian you will find in /etc/apache2/ports.conf

Listen 81 Listen 80

Second step

In some OS you will find this option in httpd.conf, if it is in Debian you will find in /etc/apache2/sites-available/, to enable in Debian and only run the command a2ensite [configuration file name].

<VirtualHost *:81> #ServerName localhost DocumentRoot /srv/www_81 </VirtualHost> <VirtualHost *:80> #ServerName localhost DocumentRoot /srv/www_80 </VirtualHost>

Note: The Servername is commented due to no need to specify a hostname, if you have a valid and public domain can this putting.

~# service apache2 reload or ~# service apache2 restart

Following example

To facilitate follow an example of the case informed, using the same port changing only the address (host).

Host 127.0.0.1 projeto.dev 127.0.0.1 localhost81

Create 2 files inside the folder called alias, which was created by you.

project81.conf <VirtualHost *:80> DocumentRoot C:/www81/projeto/public ServerName localhost81 <Directory "C:/www81/projeto/public"> Require all granted </Directory> </VirtualHost>

project_dev.conf <VirtualHost *:80> DocumentRoot C:/www/projeto/public ServerName projeto.dev <Directory "C:/www/projeto/public"> Require all granted </Directory> </VirtualHost>

Inside the httpd.conf file remains the way you have already configured it.

I believe is in a way suitable for what you want and do not need to specify the port :), will only change the host (address) typed in the browser URL.

Att.

  • I created one on hosts in the operating system to test I used localhost81

  • If it is not in the same OS (Operating System), you will have to add in each host localhost81 solving to the IP of the machine that is running apache service, and in apache you configure the Virtualhost attributing the Servername localhost81, except that when accessing via browser you will have to access as follows http://localhost81:81. I usually use it as follows, http://[IP]:80 or http://[IP]:81, and assign the displayed configuration accepted.

  • For now it is on the same operating system, but I wanted to get ready to be accessed from the local network there on the server

  • Interesting that only works for localhost81, if adding another vhost does not work

  • Which server operating system, example for Freebsd you configure directly in httpd.conf, already in Debian you create a configuration file and then you give an a2ensite [filename]. Plus the settings added in this file are usually the same, remembering that after completing the settings you should restart the apache service.

  • I tried to put in the comment only that did not give :), I edited the answer by putting an example to facilitate ;).

Show 1 more comment

0

I think all that’s left is to bug the httpd.conf file

Listen 0.0.0.0:81

For access change the door after the (2 points)

Ex:

http://localhost:81
http://localhost:82

To work on all network machines use the IP of the machine apache is configured on.

Ex:

http://192.168.0.43:81
http://192.168.0.43:82

Browser other questions tagged

You are not signed in. Login or sign up in order to post.