M
M
magary42016-02-18 12:19:46
linux
magary4, 2016-02-18 12:19:46

How to run 2 sites locally?

I have site1.conf
running

<VirtualHost 127.0.0.1:80>
  
    ServerName dt.dev
    ServerAlias www.dt.dev
.....

add a second
<VirtualHost 127.0.0.1:8888>
    ServerName  www.ez.dev
    ServerAlias ez.dev

I do a2ensite then reload
but it always opens only the 1st site
also tried for both
I want dt.dev to open one site, and ez.dev the second

Answer the question

In order to leave comments, you need to log in

4 answer(s)
G
Gasoid, 2016-02-18
@magary4

<VirtualHost 127.0.0.1:80>
    ServerName  www.ez.dev
    ServerAlias ez.dev

the virtualhost should be the same, only the domain changes,
then you need to bind the name with ip,
it is done in the file etc / hosts
127.0.0.1 ez.dev
127.0.0.1 dt.dev

S
Saboteur, 2016-02-18
@saboteur_kiev

Virtualhost does not work by ports, but by dns name.
The port (or ports) to listen on is defined globally.
When you enter the site, the web server looks at which domain name you got to it, and depending on the availability of the necessary virtualhosts with the specified names, it throws you into the desired documentroot. If a suitable virtualhost is not found, it throws on the one that you have specified by default (the first one).
So it's right to do

<VirtualHost dt.dev>
 ServerName dt.dev
 ServerAlias www.dt.dev

<VirtualHost ez.dev>
    ServerName  www.ez.dev
    ServerAlias ez.dev

in the system hosts file (for example c:\windows\system32\drivers\etc\hosts or /etc/hosts)
127.0.0.1 ez.dev
127.0.0.1 www.ez.dev
127.0.0.1 dt.dev
127.0.0.1 www.dt.dev

N
Nazar Mokrinsky, 2016-02-18
@nazarpc

Did you specify port 8888 in ez.dev?
In general, put port 80 in both cases.

A
Azazel PW, 2016-02-19
@azazelpw

site1.conf
DocumentRoot "/var/www/site1"
ServerName site1.local
ServerAlias ​​site1.local
AllowOverride All
RewriteEngine On
Options Indexes FollowSymlinks
ErrorLog /var/www/site1-error.log
LogLevel warn
site2.conf
DocumentRoot "/var/www/ site2"
ServerName site2.local
ServerAlias ​​site2.local
AllowOverride All
RewriteEngine On
Options Indexes FollowSymlinks
ErrorLog /var/www/site2-error.log
LogLevel warn

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question