0

I have never set up such setting in before but I need to add new Virtual host web-site for apache2 web-server in Ubuntu 12.04.

**I need to create a new conf file like /etc/apache2/sites-available/default for /var/www/sha-prc-corporate then use below command to enable the setting.

sudo a2ensite mynewsite sudo service apache2 restart**

My question is if above method is correct? Also how to write it for the new conf file for /etc/apache2/sites-available/mynewsite?

Thanks for any advice.

Below pictures shows current setting for the web-server: enter image description here --> This is default file

enter image description here--> All related files locates under /etc/apache2

enter image description here--> This is apache2.conf file

1 Answer 1

0

Your configuration seems to be correct, but it's difficult to parse a GIF file :)
Commands you showed are ok. If you create a my_site.conf in the /etc/apache2/sites-available and then you run a2ensite my_site, it automatically creates a symbolic link to /etc/apache2/sites-enabled, in such a way enabling the VirtualHost.

Keep in mind that your VirtualHost, as I see, has no ServerName; it can cause conflict with the default one.

To match a specific URL, just add to your VirtualHost following directives:

ServerName myname.com
ServerAlias *.myname.com  
5
  • Hi Echoes_86, Thank you for your reply! You are right. I also think it is strange for the default file. I will have a try for your advice. But could you help to explain more for ServerAlias? When should we use it? Commented Sep 27, 2016 at 7:56
  • The ServerAlias directive sets the alternate names for a host, for use with name-based virtual hosts. It means that when you make a request to your webserver, it catches the URL requested and compares it with the ServerName directive in VirtualHost. If no match is found, it tries using ServerAlias directive, that can add some alternate names. If a match is found, request is served.
    – Echoes_86
    Commented Sep 27, 2016 at 8:02
  • Most common case: ServerName my-site.com ServerAlias www.my-site.org
    – Echoes_86
    Commented Sep 27, 2016 at 8:03
  • You're welcome. If it's ok, Upvote/Accept my answer, so it's marked as resolution for the case.
    – Echoes_86
    Commented Sep 27, 2016 at 8:26
  • OK, I just finished the accept. Pls check. Commented Sep 27, 2016 at 8:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .