VirtualHost error. Apache fails with this configuration - dns

I am trying to setup a Linode VPS. VirtualHost configuration is as follows:
# domain: regenucell.com
# public: /var/www/html/regenucell.com/public_html/
<VirtualHost *:80>
# Admin email, Server Name (domain name), and any aliases
ServerAdmin webmaster#regenucell.com
ServerName regenucell.com
ServerAlias regenucell.com www.regenucell.com
# Index file and Document Root (where the public files are located)
DirectoryIndex index.html index.php
DocumentRoot /var/www/html/regenucell.com/public_html
# Log file locations
LogLevel warn
ErrorLog /var/www/html/regenucell.com/log/error.log
CustomLog /var/www/html/regenucell.com/log/access.log combined
</VirtualHost>
Whenever I do sudo a2ensite regenucell.com.conf and sudo systemctl reload apache2 , I get the following error
Job for apache2.service failed because the control process exited with error code.
See "systemctl status apache2.service" and "journalctl -xe" for details.
What am I missing here? I spent the whole night trying to figure out what I missed and yet I am nowhere.

Found the reason. It was because log folder and log files did not exist. After I created log folder and inside files (log/error.log and log/access.log) error was gone.

Related

Apache default root doesn't change for my domain in linux server

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.

Run NodeJS app on httpd subdomain

Thanks in advance for your help,
I want to launch a nodeJS application through httpd (RedHat) in a server that has a lot of VirtualHosts, so I went to the httpd conf file located at /etc/httpd/conf/httpd.conf and added in the end of the file the following configuration:
<VirtualHost *:80>
ServerName subdomain.example.com
ProxyPreserveHost on
ProxyPass / http://localhost:8080/
</VirtualHost>
My NodeJS app is running on localhost:8080 but when I go to subdomain.example.com I am just getting a Server Not found error. Tried a lot of combinaisons in the httpd config file that I have found in the internet but in vain. I restart the httpd service everytime I did a change to the config file by running service httpd restart
This was only a DNS propagation issue. Fixed by adding an A record to the DNS entries.

Apache Multi-project configuration

I have a server with an ip: XXX.XXX.XXX.XXX
In my server, i have several projects in the folder /var/www:
/var/www/project1
/var/www/project2/trunk/webroot
...
My 000-default.conf is like this:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Currently I access into them through the following url:
XXX.XXX.XXX.XXX/project1
XXX.XXX.XXX.XXX/project2/trunk/webroot
...
I have a domain that targets to my server
domain.com -> XXX.XXX.XXX.XXX
My intention is to create a subdomain for each project, and each subdomain points to the target folder of the project:
project1.domain.com -> XXX.XXX.XXX.XXX/project1
project2.domain.com -> XXX.XXX.XXX.XXX/project2/trunk/webroot
(I think the best solution will be that XXX.XXX.XXX.XXX/project2 targets directly to XXX.XXX.XXX.XXX/proyect2/trunk/webroot)
I have read that it will be great that each project has its own .conf file in apache, and enabling each site separately.
But I think that if I create a VirtualHost *:80 for each project (project1.conf, project2.conf) they will be in conflict and I dont know how to do it.
Can anybody help me?
Regards.
Virtual Host is the way to go... create one virtual host for each domain pointing to a folder on your server where to webpage is sotored.
Listen 80
<VirtualHost *:80>
DocumentRoot "/www/example1"
ServerName www.example.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/www/example2"
ServerName www.example.org
</VirtualHost>
Etc... One VirtualHost for each domain / DocumentRoot convination
Soruce: https://httpd.apache.org/docs/current/vhosts/examples.html
##################### EDIT
I have tested it on my own server
Whithout touching the default.conf file I have created two new config files
root#raspberrypi:/etc/apache2/sites-available# pwd
/etc/apache2/sites-available
root#raspberrypi:/etc/apache2/sites-available#
Please ignore the default files I have not touched them I have just created two new files named project1.... and project2....
root#raspberrypi:/etc/apache2/sites-available# ls
000-default.conf project1_domain_com.conf
default-ssl.conf project2_domain_com.conf
root#raspberrypi:/etc/apache2/sites-available#
root#raspberrypi:/etc/apache2/sites-available# cat project*
<VirtualHost *:80>
DocumentRoot "/var/www/projects/project1/"
ServerName project1.domain.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/var/www/projects/project2/"
ServerName project2.domain.com
</VirtualHost>
root#raspberrypi:/etc/apache2/sites-available#
ENABLING SITES
root#raspberrypi:/etc/apache2/sites-available# a2ensite project1_domain_com.conf
Enabling site project1_domain_com.
To activate the new configuration, you need to run:
service apache2 reload
root#raspberrypi:/etc/apache2/sites-available# a2ensite project2_domain_com.conf
Enabling site project2_domain_com.
To activate the new configuration, you need to run:
service apache2 reload
root#raspberrypi:/etc/apache2/sites-available#
RELOAD APACHE
root#raspberrypi:/etc/apache2/sites-available# /etc/init.d/apache2 reload
[ ok ] Reloading apache2 configuration (via systemctl): apache2.service.
root#raspberrypi:/etc/apache2/sites-available#
################# SUBDOMAIN EDIT
For example I have a single server with an IP XXX.XXX.XXX.XXX that have multiple domains registered (15 domains now).
I have one virtual host entry for each domain that works this way:
domain1.example.com -> Load the domain1 web index.html page (without /nothing/else )
domain2.example.com -> Load the domain2 web index.html page hosted on another folder expecified on the second virtual host.
And finally ussing a2ensite or a2dissite I enable or disable the website as a web hosting provider do...
If for any reason you need that accessing the host domain3.something.com it redirects to domain3.something.com/something/diferent ... it should be done on your server ussing .htaccess file and its a entirely diferent question :D

Files in my DocumentRoot directory are not being served when I enter their URLs in my web browser

I have installed Apache 2.4.9 on my linux machine. I am trying to set up a local website for a school project and I have added the following to httpd.conf:
ServerName localhost
DocumentRoot "/home/jared/classes/cs275-spring/final_project"
I have verified that the Directory supplied to DocumentRoot is valid. Under this directory, there is a file called hello.html. When I try to access the file by going to localhost/hello.html, I am greeted with a 404 page. However, just going to "localhost" seems to work fine. Any ideas as to what's wrong here?
Try the following config after restarting your HTTPD server:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName localhost
DocumentRoot /home/jared/classes/cs275-spring/final_project
</VirtualHost>

Apache2 - Trouble Adding Subdomain

I have a Linode server running Ubuntu 11 and Apache2 and I'm trying to get a subdomain working. This is my mywebsite file in sites-available folder. I've tried putting the top part in its own file testing.mywebsite and reloading apache2 with no luck.
<VirtualHost *:80>
DocumentRoot /home/user2/www
ServerName testing.mywebsite.com
</VirtualHost>
<VirtualHost *:80>
ServerAdmin email#gmail.com
ServerName mywebsite.com
ServerAlias *.mywebsite.com
ServerAlias 192.155.90.135
#Index file and Document Root (where the public files are located)
DirectoryIndex index.html index.php
DocumentRoot /home/user/public/mywebsite/www
#Log file locations
LogLevel warn
ErrorLog /home/user/public/mywebsite/log/error.log
CustomLog /home/user/public/mywebsite/log/access.log combined
</VirtualHost>
I have a website up and running and apache can find all the files in /home/user/public/mywebsite/www but when I go to the testing subdomain, my browser can't find it. I'm pretty unfamiliar with apache2, so any help is appreciated. Thanks.
Are your DNS records configured to point your computer at the desired hostname to your server's IP address when it resolves? Or, are you overriding with editing /etc/hosts?
I am somewhat unsure what "my browser can't find it" means, so please clarify if the above questions don't get you closer to your problem. It would be worth checking your log files for Apache in your specified paths and /var/log/apache2/.

Resources