-1

I found this post and updated my config.

I have this reverse proxy configuration on Apache.

<VirtualHost *:80>
    ServerName a123.com
    ServerAlias www.a123.com

    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteRule ^/?(.*) https://%{SERVER_NAME}/ [R,L]
</VirtualHost>
<VirtualHost *:443>
    ProxyPreserveHost On
    ProxyPass "/test2/" "http://localhost:48630"
    ProxyPassReverse "/test2/" "http://localhost:48630"
    ProxyPass "/" "http://localhost:5000/"
    ProxyPassReverse "/" "http://localhost:5000/"
    ErrorLog /var/log/httpd/a123-error.log
    CustomLog /var/log/httpd/a123-access.log common
    SSLEngine on
    SSLCertificateFile /etc/ssl/certs/a123.com.crt
    SSLCertificateKeyFile /etc/ssl/private/a123.com.key
</VirtualHost>

How should this config be changed to access both www.a123.com and test2.a123.com subdomains?

I can only access www.a123.com or www.a123.com/test2/ now with this configuration?

yW0K5o
  • 61
  • 7

2 Answers2

1

this is a virtualhost configuration. it will be applied for all the calls to your server using domain matching ServerName and ServerAlias directive. You can have more alias.

ServerAlias www.a123.com test2.a123.com 

or if you want all subdomain:

ServerAlias *.a123.com 
djv
  • 81
  • 5
  • Thank you. I'll try it later and let you know if it works. – yW0K5o Dec 06 '18 at 16:09
  • I tested, it works partially. Both main site and sub-domain point to the same place. How to rewrite ProxyPass or RewriteRule to point to different places for main and sub-domain sites? – yW0K5o Dec 06 '18 at 21:48
-1

You can write two VirtualHosts one for each domain and pass them to different locations.

Edit: 2 Virtual Host and no SSL

Edit: All subdomains must be allowed in DNS configuration as *

<VirtualHost *:80>
    ServerName a123.com
    ServerAlias www.a123.com
    ProxyPreserveHost On
    ProxyPass "/" "http://localhost:5000/"
    ProxyPassReverse "/" "http://localhost:5000/"
    ErrorLog /var/log/httpd/a123-error.log
    CustomLog /var/log/httpd/a123-access.log common
</VirtualHost>

<VirtualHost *:80>
    ServerName test2.a123.com
    ServerAlias www.test2.a123.com
    ProxyPreserveHost On
    ProxyPass "/" "http://localhost:48630/"
    ProxyPassReverse "/" "http://localhost:48630/"
    ErrorLog /var/log/httpd/test-a123-error.log
    CustomLog /var/log/httpd/test-a123-access.log common
</VirtualHost>
yW0K5o
  • 61
  • 7
Spirit
  • 224
  • 1
  • 5
  • Could you give working example? Thanks. – yW0K5o Dec 08 '18 at 13:18
  • I have added some code. – Spirit Dec 08 '18 at 16:32
  • I put your code in 1 file. I can hit main website. When I try to hit subdomain I'll receive the error "server IP address could not be found." – yW0K5o Dec 08 '18 at 16:52
  • Have you looked in the apache error log? – Spirit Dec 08 '18 at 18:31
  • Error log shows some SSL errors. I changed DNS record to accept all requests as *.a123.com. When I try to hit test2.a123.com it redirects me to the main site a123.com – yW0K5o Dec 08 '18 at 20:32
  • If you have only a SSL Cert for a123.com and no wildcard cert, then you can't use https://test2.a123.com. You need to have a valid cert for the subdomain. – Spirit Dec 08 '18 at 20:41
  • I don't care about SSL errors. – yW0K5o Dec 08 '18 at 21:02
  • I have answered a last try, all without SSL this time. If this does not work. I have no idea and recommend nginx. – Spirit Dec 08 '18 at 21:07
  • I added 1 modification in the 2nd VirtualHost `ServerAlias www.test2.a123.com` to your answer and it starts working. I am accepting your answer. Congratulations ! Thank you very much ! – yW0K5o Dec 09 '18 at 12:44