I have, for example site1.com, site2.com, configured with their own virtual hosts in their own files in the apaches enabled and available folders, in their own physical folders on the server and with different .htaccess and they are working fine. Now I want all the other domains that are not separately configured (for example site3.com, site4.com ....) to have one same virtual host, same physical folder, and to execute the same /folder1/folder2/index.php file. So far, I've made some virtual hosts but all I get is "It's working", probably because everything is redirected from the default virtual host to the /var/www. But if I set the DocumentRoot directive in that file, the .htaccess for some reason is not working, and I said that for the defined sites are working OK. What the virtual host file should be called, what should be it's content?
You can define a VirtualHost container that has as many ServerAlias entries as you need.
Here's a very simplified example:
<VirtualHost *>
ServerName site3.com
ServerAlias site4.com
DocumentRoot /var/www/folder1/folder2
</VirtualHost>
If you've already tried creating vhost files, have you restarted apache?
Where to put the vhost files depends on what distro you're using. If you're not familiar with where stuff goes on your distro, check http://wiki.apache.org/httpd/DistrosDefaultLayout.
Related
When I go to my ip address an index file is served.
However when I navigate to my domain name a page isn't served.
Apache won't serve content from my (domain name) web directory.
I don't plan to install PHP or a Database until the virtual hosts implementation is legit.
I've reinstalled my image more times than I can count to get my websites migrated to a virtual server. The biggest sticking point is configuring the virtual hosts. My latest attempt was using this blog article:
https://www.tecmint.com/install-apache-with-virtual-hosts-on-debian-10/
Before that it was this article in previous attempts:
https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mariadb-php-lamp-stack-on-debian-10
I looked at this article too:
https://linuxize.com/post/how-to-set-up-apache-virtual-hosts-on-debian-10/
I saw mentions of a user called www-data during my internet search but it isn't mentioned in the three blog posts I cited.
My hosting company keeps telling me to use Plesk but they didn't configure the shared hosting environment for the migration extension.
So I can't use Plesk to migrate and they charge me a monthly fee for the Plesk license if it is installed on the image.
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
ServerAdmin webmaster#example.com
DocumentRoot /var/www/html/example.com
<Directory /var/www/html/example.com>
Options -Indexes +FollowSymLinks
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined
/etc/apache2/sites-available/example.com.conf
I looked at the domain name in other browsers and Chrome is forcing HTTPS at my request. I didn't get around to reinstalling the SSL/TLS because of the confusion with the virtual hosts. So basically the page has been live the entire time but Chrome wouldn't connect because a secure connection was unavailable.
This probably is not the correct answer, but I went into my file /etc/apache2/sites-enabled/000-default.conf
and changed the lines from:
#<VirtualHost *:80>
<VirtualHost *:8888>
#DocumentRoot /var/www/html
DocumentRoot /home/MyPath/Drives/02000/www
I know in Apache, there are virtual hosts. When a request is given, it goes and search between these virtual hosts to see if there are server name like request. It takes its option back like document root and others I have this file in /etc/httpd/sites-enabled:
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/example.com/html
ErrorLog /var/www/example.com/log/error.log
CustomLog /var/www/example.com/log/requests.log combined
</VirtualHost>
I defined all directories as well like /var/www/example.com/html and after all that, I have a file named /etc/httpd/conf at its last line I added this code:
Include sites-enabled/*.conf
After that when I restart httpd it performs complete with no errors, but it doesn't work and it goes to its default root. Where is the problem?
Once you create a virtual host configuration file, in your example, /etc/apache2/sites-available/example.com.conf
You need to use the command as super user
a2ensite example.com
And then restart Apache:
systemctl reload apache2
You can tell what virtual hosts are up and running by the command:
apache2ctl -S
i solve it just with replacing star with my local ip in linux in virtualhost tag
<VirtualHost ip:80>
after too many examination it works finally.there was no problem in other places.
Can it be dangerous to let domains linked to your apache2 without virtualhost to catch them ? Is it possible to configure apache to reject unknown domains ?
ex: domain is not referenced in a virtual host, therefore when apache2 answer to it, it takes the first virtualhost referenced on the server.
the same way, when we enter the ip address of the server, the first VH is taken to answer to the request.
Generally I would not consider it "dangerous", it more comes down to how do you want your server to behave. Personally, unless there is a reason not to do so, I always block unknown domains.
Apache can reject undefined domains by simply putting "catch all" domain at the top of the virtual hosts configuration file (or, in case you are using multiple conf files, in the alphabetically first file), and configuring that domain to unconditionally respond with 403 (or you can configure any other respond you find suitable):
<VirtualHost *:80>
ServerName default
RewriteRule ^ - [F]
</VirtualHost>
<VirtualHost *:80>
ServerName example.com
# ...
</VirtualHost>
I have set up a linux box mainly for testing and I have got to a stage were apache, mysql and php are running. I followed tutorials on how to set up virtual hosts so I can point domains to it but something strange is happening.
This is my httpd-vhosts.conf file that I have included in my httpd.conf file:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName thedomain.co.uk
DocumentRoot /var/www/thedomain
</VirtualHost>
When I go to thedomain.co.uk it is pointing to the correct place as you'd expect. But when I go to my servers ip, internal or external it is going to the same directory as the virtual host. Could you guys think of any reason that is? I would expect it to go to /var/www/html by default? Oh and I'm running CentOS 6.3
Thanks in advance for any answers!
You have used wildcard to point everything at DocumentRoot /var/www/thedomain
You need to create second listing :
<VirtualHost myotherdomain.co.uk:80>
ServerName myotherdomain.co.uk
DocumentRoot /var/www/myotherdomain
</VirtualHost>
where your other domain is whatver ip and the document root, points to your choise.
The first vhost listing is also used as the default ... so if you were to use localhost it would resolve to whatever is first in list.
I have done this in IIS7.5 with ease.
Say I have a domain mbdev.myftp.biz.
On IIS I have setup sites but each one has a different port.
Example:
mbdev.myftp.biz:8004
mbdev.myftp.biz:8006
The only thing that is different is the port for the site. Those above URL's got to actual sites on the IIS box.
How can I accomplish the same thing with APACHE? Having the site be on a specific port?
For Example:
mbdev.myftp.biz:8600
mbdev.myftp.biz:8601
Apache accomplishes this through the VirtualHost directive. Documentation for version 2.4 can be found on http://httpd.apache.org/docs/2.4/vhosts/index.html and more specifically the configuration directive http://httpd.apache.org/docs/2.4/mod/core.html#virtualhost
An example virtualhost config directive pulled from the link above:
<VirtualHost 10.1.2.3:80>
ServerAdmin webmaster#host.example.com
DocumentRoot /www/docs/host.example.com
ServerName host.example.com
ErrorLog logs/host.example.com-error_log
TransferLog logs/host.example.com-access_log
</VirtualHost>