I have bought a server from linode.com and set it up with my purchased domain from namecheap. Setting up the DNS worked as expected and I followed the official documentation from linode.
But whenever I am trying to set up a subdomain in the same server, despite following the same documentation, for some reason I can't set it up.
Here is the config:
Server: Apache on Ubuntu 18.04
Domain: randomxyz.xyz
Here are the steps that I followed:
Created AAAA record in Linode Manager Panel.
IP -> Server IP.
Hostname -> temp.
SSH into the server.
created a folder named temp.randomxyz.xyz inside var/www/html.
created public_html, log and backups folders for temp.randomxyz.xyz.
created temp.randomxyz.xyz.conf in etc/apache2/sites-available
put Vhost config in the conf file:
# domain: randomxyz.xyz
# public: /var/www/html/randomxyz.xyz/public_html/
<VirtualHost *:80>
# Admin email, Server Name (domain name), and any aliases
ServerAdmin ok#randomxyz.xyz
ServerName temp.randomxyz.xyz
ServerAlias temp.randomxyz.xyz
# Index file and Document Root (where the public files are located)
DirectoryIndex index.html index.php
DocumentRoot /var/www/html/temp.randomxyz.xyz/public_html
# Log file locations
LogLevel warn
ErrorLog /var/www/html/temp.randomxyz.xyz/log/error.log
CustomLog /var/www/html/temp.randomxyz.xyz/log/access.log combined
</VirtualHost>
Enable the new configured site: a2ensite temp.randomxyz.xyz
Reload Apache: systemctl restart apache2
I have waited for more than 48 hours. The Subdomain is not working.
What am I missing here?
Do I have to do something in namecheap manager?
Related
I am currently trying to setup an virtual hosts following this tutorial on DigitalOcean.
The dummy-site I am trying to serve is under /var/www/example/html/index.html. I have not registered an official domain but setup /etc/hosts/ to resolve example.com to the IP address of my server.
I created another conf file called example.conf under /etc/apache2/sites-available and enabled it with sudo a2ensite example.conf and disabled the 000-default.conf.
Now whenever I go to example.com in my browser I get served:
.
This is the same page I would get when directly going to the IP address of my server. Only when I got directly to example.com/example/html I get served the correct index.html.
My current config looks like this:
<VirtualHost *:80>
ServerAdmin admin#example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
And my /etc/hosts file on my laptop like this:
#<ip-address> <hostname.domain.org> <hostname>
<server-ip> example.com
There are some other folders inside /var/www/ as the company I rented the server from had some maintenance sites preinstalled, but that shouldn't matter in this situation. (See edit, this did actually matter).
It feels like I am missing something obvious here, but I can't find a solution for my problem.
Edit:
The obvious thing I was missing, was that 2 additional sites where enabled by default as well.
One had the following contents:
# 10_froxlor_ipandport_<ip-address>.conf
# Created 28.11.2019 21:05
# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.
<VirtualHost <ip-address>:80>
DocumentRoot "/var/www/"
ServerName <predefined Server name>
</VirtualHost>
After disabling all the other sites, the request to example.com actually went to the right index.html.
I figure, that the above enabled site actually matched the request coming from my browser and showed the www root directory.
The obvious thing I was missing, was that 2 additional sites where enabled by default as well.
One had the following contents:
# 10_froxlor_ipandport_<ip-address>.conf
# Created 28.11.2019 21:05
# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.
<VirtualHost <ip-address>:80>
DocumentRoot "/var/www/"
ServerName <predefined Server name>
</VirtualHost>
After disabling all the other sites, the request to example.com actually went to the right index.html.
I figure, that the above enabled site actually matched the request coming from my browser and showed the www root directory.
I'm attempting to setup a apache2 vhost in the latest version of Ubuntu and i keep getting a "Forbidden" when trying to access the page.
I have setup a folder for this new site under
/root/websites/panel.joosh.eu/www
And this has the owner/group of root:root so i can edit it and permissions of 644
This is my vhost file in sites-avaliable (yes i also enabled it)
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName panel.joosh.eu
ServerAdmin josh#joosh.eu
DocumentRoot /root/websites/panel.joosh.eu/www
<Directory /root/websites/panel.joosh.eu/www>
Order allow,deny
Allow from all
Require all granted
</Directory>
ErrorLog /root/websites/panel.joosh.eu/logs/error.log
CustomLog /root/websites/panel.joosh.eu/logs/access.log combined
Ive tried everything but i still get forbidden, any ideas?
sudo chown -R www-data:www-data /root/websites/panel.joosh.eu/www
your permission is wrong
Understanding and Using File Permissions
move your project folder to /var/www/html and try
Apache Server Unable to host multiple domain on single Public IP running on Windows Server 2016
Error:"Not Found The requested URL / was not found on this server." 404 Not Found
Progress so far :
1)Edited Windows hosts file "C:\Windows\System32\drivers\etc\hosts": to below
127.0.0.1 localhost
::1 localhost
127.0.0.1 koffeeroasters.com
2)Changes made in the httpd.conf file of apache is below
changed
#Include conf/extra/httpd-vhosts.conf
to
Include conf/extra/httpd-vhosts.conf
also changed
#LoadModule rewrite_module modules/mod_rewrite.so
to
LoadModule rewrite_module modules/mod_rewrite.so
and added to the end of the file the following
# Tells Apache to identify which site by name
NameVirtualHost *:80
# Tells Apache to serve the default WAMP Server page to "localhost"
<VirtualHost 127.0.0.1>
ServerName localhost
DocumentRoot "C:/wampstack/apache2/htdocs"
</VirtualHost>
# Tells Apache to serve Client 1's pages to "client1.localhost"
# Duplicate and modify this block to add another client
<VirtualHost 127.0.0.1>
# The name to respond to
ServerName koffeeroasters.com
ServerAlias www.koffeeroasters.com
# Folder where the files live
DocumentRoot "C:/wampstack/apache2/htdocs/koffeeroasters.com/"
# A few helpful settings...
<Directory "C:/wampstack/apache2/htdocs/koffeeroasters.com/">
Order Allow,Deny
Allow from all
# Enables .htaccess files for this site
AllowOverride All
</Directory>
# Apache will look for these two files, in this order, if no file is specified in the URL
DirectoryIndex index.html index.php
</VirtualHost>
Other details
I am using apache server on bitnami wampstack.
Site is available when typed the address "koffeeroasters.com" from the servers browser.
A reason for it which I know no solution of (refered from apache docs "https://httpd.apache.org/docs/2.4/vhosts/examples.html") :
Note :
Creating virtual host configurations on your Apache server does not magically cause DNS entries to be created for those host names. You must have the names in DNS, resolving to your IP address, or nobody else will be able to see your web site. You can put entries in your hosts file for local testing, but that will work only from the machine with those hosts entries.
Thanks a bunch. All help appreciated.
Try changing this:
<VirtualHost 127.0.0.1>
to
<VirtualHost *:80>
This means allow any other IPs connect on port 80, which should get you going. Trying to match the localhost is doing more than you probably need, unless you are public facing server, in which case you will not want to do this.
This is what I have in my "etc/hosts" file:
127.0.0.1 localhost
127.0.1.1 gotqn-System-Product-Name
127.0.0.1 depot.yourhost.com
and this is what I have added in the apache2.conf file:
<VirtualHost *:80>
ServerName depot.yourhost.com
DocumentRoot "/home/gotqn/Aptana Projects/depot/public/"
<Directory "/home/gotqn/Aptana Projects/depot/public">
AllowOverride all
Options -MultiViews
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
When I type http://localhost/ my browser lists all my files in the "var\www" folder and when I type http://depot.yourhost.com/ it displays the following error:
We're sorry, but something went wrong.
I have checked the production.log file of my rails applications and it says:
Connecting to database specified by database.yml
Started GET "/" for 127.0.0.1 at 2013-01-13 20:32:41 +0200 Processing
by StoreController#index as HTML Completed 500 Internal Server Error
in 3ms
ActiveRecord::StatementInvalid (Could not find table 'carts'):
app/controllers/application_controller.rb:46:in rescue in
current_cart' app/controllers/application_controller.rb:44:in
current_cart' app/controllers/store_controller.rb:11:in `index'
I suppose that there is something wrong with my database configuration as the table exists but it is not found.
Anyway, my questions is how the hosts file knew that "depot.yourhost.com" means to open the rails applications and "localhost" do list my "var\www" folder - I have thought that RoR is using port 3000.
Why there is no conflict for port 80?
Rails applications run under port 3000 when running with the lightweight Webrick server. Since you are running Apache with mod_passenger, the application will be available at port 80 according to your Apache configuration.
The hosts file contains an entry 127.0.0.1 depot.yourhost.com which directs that domain name to your local adapter 127.0.0.1. The hosts file should always be checked before a nameserver needs to be consulted to retrieve a name's address.
Next, your Apache configuration includes a VirtualHost which is listening on all network adapters due to the * in
<VirtualHost *:80>
Your Apache configuration must be setup to use name-based virtual hosting, after which the ServerName variable is matched against the HTTP_HOST request header which was supplied by your request to depot.yourhost.com.
Therefore, you can have as many VirtualHosts as needed all using port 80 on the same IP address, and Apache will decide which to route the request to based on the HTTP_HOST header.
Finally, mod_passenger will detect if an application is a Ruby on Rails application by inspecting the directory contents around the DocumentRoot which you have specified in the VirtualHost configuration. If it finds the public directory as its DocumentRoot and a RoR application at a level higher, Passenger will attempt to start the Rails app.
Now, as to why you are getting a directory listing from localhost... Elsewhere in your Apache configuration you must have a VirtualHost which matches the ServerName localhost and sets its DocumentRoot to /vart/www.
<VirtualHost *:80>
ServerName localhost
# or...
ServerAlias localhost
</VirtualHost>
If you are seeing the contents of the directory listed out rather than a 403 Forbidden (absent an index file like index.html), it is because the Apache server config or VirtualHost config does not include the directive:
Options -Indexes
Add that in the global httpd.conf to prevent listing directories server-wide.
Lets' asume I have 1 domain on a Ubuntu Server in the following directory:
/var/www/domain1.com/httpdocs
and that the ip address is 100.100.100.100
If I go to www.domain1.com, Apache will server the files inside the httpdocs folder.
How can I avoid that if the following file exists:
/var/www/domain1.com/privatefile.html
.. apache shows it by going to:
http://100.100.100.100/domain1.com/privatefile.html
In other words, I want to display the content in the httpdocs only, no by ip address.
In a vhost setup, Apache will use the first vhost defined as the default one to serve when a request comes in by IP. So just make a "dummy" vhost that points nowhere, and make sure it's the first one in the config file:
<VirtualHost *:80>
ServerName nothing.nowhere
ServerAdmin nobody#nothing.nowhere
DocumentRoot /var/empty
<Directory /var/empty>
Order Allow,Deny
</Directory>
</VirtualHost>