2

I have a valid IP, e.g. x.x.x.x, and a domain, e.g. site.com which point to x.x.x.x.

First, I need to redirect any request from port 80 to 443 (security issue). Second, for every request sent to my IP, I want apache to show "Hello it's working" (/var/www/index.html) and everyone request to my domain to show the real site.

I tried this, but it did not work:

<VirtualHost x.x.x.x:433>
    ServerName x.x.x.x
    ServerAlias x.x.x.x
    DocumentRoot /var/www/
    DirectoryIndex index.html
    Options -Indexes
</VirtualHost>

<VirtualHost site.com:443>
...
</VirtualHost>
1

1 Answer 1

0

for redirection:

NameVirtualHost *:80
<VirtualHost *:80>
   ServerName www.yourdomain.com
   Redirect / https://www.yourdomain.com
</VirtualHost>

<VirtualHost _default_:443>
   ServerName www.yourdomain.com
   DocumentRoot /usr/local/apache2/htdocs
   SSLEngine On
# etc...
</VirtualHost>

for domain separation:

<VirtualHost *:80>
    # This first-listed virtual host is also the default for *:80
    ServerName www.example.com
    ServerAlias example.com 
    DocumentRoot "/www/domain"
</VirtualHost>

<VirtualHost *:80>
    ServerName other.example.com
    DocumentRoot "/www/otherdomain"
</VirtualHost>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.