1

here the scenario:

I have example.com

<VirtualHost *:80>
        Redirect Permanent "/" "https://example.com"
</VirtualHost>

the above works perfectly(it redirects to the configuration of <VirtualHost *:443>...</VirtualHost>),

now I'm trying to add another virtual host dev.example.co.uk to this server so it serves both websites on port 80

<VirtualHost *:80>

     ProxyPreserveHost On
     ServerName dev.example.co.uk                                                                                                                                                                      


     Timeout 2400
     ProxyTimeout 2400
     ProxyBadHeader Ignore


     SetEnv proxy-initial-not-pooled
     SetEnv proxy-nokeepalive 1

     ProxyPass / http://127.0.0.1:8888/  retry=1 acquire=3000 timeout=600 Keepalive=On
     ProxyPassReverse / http://127.0.0.1:8888/

</VirtualHost>

for some reason whenever I type dev.example.co.uk in a browser, it redirects to example.com which eventually redirects to https://example.com

I'm guessing it still picking up the first configuration.

basically what I really want is when I type dev.example.co.uk it picks the configuration of its own virtual host and not the first one.

what am I doing wrong here?

nafas
  • 113
  • 5
  • Is you second block actually inside a `` block or not? It's not clear from the excerpts given. Running `httpd -S` can be useful to make sure Apache is picking up the various virtual hosts correctly. Also you should ideally have a ServerName directive in each one. – USD Matt Apr 27 '18 at 09:26
  • @USDMatt soz bro , it was a typo, yes its inside block – nafas Apr 27 '18 at 09:30
  • @USDMatt `httpd` command not found, I'm running it on `ubuntu 16.04` – nafas Apr 27 '18 at 09:31
  • @USDMatt mate ur last part of ur comment did it for me. I feel so stupid, I was missing ServerName on the first configuration, please answer the question so I can accept it, ty – nafas Apr 27 '18 at 09:36

1 Answers1

1

You can try this:

<VirtualHost *:80>
    ServerName example.com
    #ServerAlias *.example.com
    Redirect Permanent "/" "https://example.com"
</VirtualHost>

Feel free to uncomment the serverAlias directive according to your needs

Andrew Schulman
  • 8,561
  • 21
  • 31
  • 47
bgtvfr
  • 1,224
  • 10
  • 19