Create Apache Vhosts on Windows: Does not exceed htdocs

Asked

Viewed 194 times

-1

I’m following a tutorial on the net teaching to create Virtualhosts on Apache in Windows environment

Man http-vhosts.conf

<VirtualHost _default_:80>
DocumentRoot "${SRVROOT}/htdocs"
#ServerName www.example.com:80
</VirtualHost>

<VirtualHost *:80>
    ServerName fielcard.net.br
    DocumentRoot "D:\Trabalhos\host\htdocs\fielcard.net.br"
    ErrorLog "logs/projeto-error.log"
    CustomLog "logs/projeto-access.log" common
    <Directory "D:\Trabalhos\host\htdocs\fielcard.net.br" >
        DirectoryIndex index.php index.html index.htm
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

There are more things. But with commented lines.

Man hosts of windows

127.0.0.1 fielcard.net.br

Again: There are more things. But with commented lines.

Apache 2.4 PHP 7.3

Attempts:

ServerName fielcard.net.br.local
127.0.0.1  fielcard.net.br.local

I rebooted the Apache. I restarted my Windows.

My Apache has the folder htdocs with a file index php. with just the word localhost. And inside it for every site I develop there is a folder with the name of the site.

So I wish to create a vhosts for each site.

The outworking that I’m getting, it’s always the same:

Appears

Localhost

in the Browser!

That is, it never enters the project folder!

What’s wrong?

COMPLEMENT:

I found out the following:

In the folder conf of Apache has the folder extra

Inside this folder has 2 configuration files to know:

httpd-ahssl.conf  => Configuração de Virtuais Hosts com SSL

e

httpd-vhosts.conf  => Configuração de Virtuais Hosts sem SSL

In fact, when configuring the Virtual Host for a website, was constantly redirecting to the root of htdocs and not into the website.

This is due to the fact that in the folder of fielcard.net.br, has a .htaccess redirecting all http input to https and as https entries were set their Documentroot to the root of localhost then every attempt to Virtualhost fall at the root and therefore at the index php. which contains only the word Localhost as previously stated here in the question.

Without SSL, the door and always the 80, soon, it was working to virtualization but redirecting to each new folder host nay!

Doubt now becomes another.

Here’s the new file httpd-ahssl.conf

##
## SSL Virtual Host Context
##

<VirtualHost _default_:443>
  SSLEngine on
  ServerName localhost:443
  SSLCertificateFile "${SRVROOT}/conf/ssl/server.crt"
  SSLCertificateKeyFile "${SRVROOT}/conf/ssl/server.key"
  DocumentRoot "D:/Trabalhos/host/htdocs/fielcard.net.br"
# DocumentRoot "${SRVROOT}/htdocs"
# DocumentRoot access handled globally in httpd.conf
    CustomLog "${SRVROOT}/logs/ssl_request.log" \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
    <Directory "${SRVROOT}/htdocs">
        Options Indexes Includes FollowSymLinks
        AllowOverride AuthConfig Limit FileInfo
    Require all granted
    </Directory>
</virtualhost>

<VirtualHost *:443>
  SSLEngine on
  ServerName serverone.tld:443
  SSLCertificateFile "${SRVROOT}/conf/ssl/serverone.crt"
  SSLCertificateKeyFile "${SRVROOT}/conf/ssl/serverone.key"
  DocumentRoot "D:/Trabalhos/host/htdocs/fielcard.net.br"
    CustomLog "${SRVROOT}/logs/ssl_request.log" \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
    <Directory "${SRVROOT}/htdocs">
        Options Indexes Includes FollowSymLinks
        AllowOverride AuthConfig Limit FileInfo
    Require all granted
    </Directory>
</virtualhost>

<VirtualHost *:443>
  SSLEngine on
  ServerName servertwo.tld:443
  SSLCertificateFile "${SRVROOT}/conf/ssl/servertwo.crt"
  SSLCertificateKeyFile "${SRVROOT}/conf/ssl/servertwo.key"
  DocumentRoot "D:/Trabalhos/host/htdocs/fielcard.net.br"
    CustomLog "${SRVROOT}/logs/ssl_request.log" \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
    <Directory "${SRVROOT}/htdocs">
        Options Indexes Includes FollowSymLinks
        AllowOverride AuthConfig Limit FileInfo
    Require all granted
    </Directory>
</virtualhost> 


<VirtualHost _default_:443>
  SSLEngine on
  ServerName localhost:443
  SSLCertificateFile "${SRVROOT}/conf/ssl/server.crt"
  SSLCertificateKeyFile "${SRVROOT}/conf/ssl/server.key"
  DocumentRoot "D:/Trabalhos/host/htdocs/mvc_crud_pdo"
    CustomLog "${SRVROOT}/logs/ssl_request.log" \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
    <Directory "${SRVROOT}/htdocs">
        Options Indexes Includes FollowSymLinks
        AllowOverride AuthConfig Limit FileInfo
    Require all granted
    </Directory>
</virtualhost>

<VirtualHost *:443>
  SSLEngine on
  ServerName serverone.tld:443
  SSLCertificateFile "${SRVROOT}/conf/ssl/serverone.crt"
  SSLCertificateKeyFile "${SRVROOT}/conf/ssl/serverone.key"
  DocumentRoot "D:/Trabalhos/host/htdocs/mvc_crud_pdo"
    CustomLog "${SRVROOT}/logs/ssl_request.log" \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
    <Directory "${SRVROOT}/htdocs">
        Options Indexes Includes FollowSymLinks
        AllowOverride AuthConfig Limit FileInfo
    Require all granted
    </Directory>
</virtualhost>

<VirtualHost *:443>
  SSLEngine on
  ServerName servertwo.tld:443
  SSLCertificateFile "${SRVROOT}/conf/ssl/servertwo.crt"
  SSLCertificateKeyFile "${SRVROOT}/conf/ssl/servertwo.key"
  DocumentRoot "D:/Trabalhos/host/htdocs/mvc_crud_pdo"
    CustomLog "${SRVROOT}/logs/ssl_request.log" \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
    <Directory "${SRVROOT}/htdocs">
        Options Indexes Includes FollowSymLinks
        AllowOverride AuthConfig Limit FileInfo
    Require all granted
    </Directory>
</virtualhost> 

# End SNI Demonstration Config

I don’t know if I’m doing it correctly. But when I type in the browser:

https://fielcard.net.br

Cool.

But when I type

https://mvc_crud_pdo

is opening

https://fielcard.net.br

instead of

https://mvc_crud_pdo

What is wrong now?

Another question: if this is the right way, then does that mean that for each virtual host I have to configure 3 blocks of code equal to this? If so, in a while that file will be giant!

That’s the way it is?

1 answer

0


<VirtualHost *:80>
    DocumentRoot "${SRVROOT}/htdocs"
    ServerName localhost
    ServerAlias localhost
</VirtualHost>

<VirtualHost *:80>
    ServerName fielcard.net.br
    ServerAlias fielcard.net.br
    DocumentRoot "D:\Trabalhos\host\htdocs\fielcard.net.br"
    ErrorLog "logs/projeto-error.log"
    CustomLog "logs/projeto-access.log" common
    <Directory "D:\Trabalhos\host\htdocs\fielcard.net.br" >
        DirectoryIndex index.php index.html index.htm
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>
  • Only a blank page (almost) appears with only the word localhost which is the index.php page I created in the htdocs root of the new Apache folder directory

  • Checks whether the line that loads the module is not commented on. It starts with "Loadmodule vhost_alias_module". Remember to restart the service after changes.

  • not commented Leonardo. It was the first thing I did. And yes. I restarted not only Apache but also Windows!

Browser other questions tagged

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