Apache httpd domain and ip separation - apache

I have been trying this for hours and am getting pretty frustrated. I am trying to use a ReadyNAS Pro as a webserver. It uses Apache for its web interface. I would like to use that interface when I address the device via IP address, but I also have my domain name pointing to it. When I use my domain name I want it to display my website (with wildcards for the website's pages). I have tried using mod-rewrite without much success. It seems to break the ReadyNAS web interface. I have tried adding a named virtual host, but I don't have much experience with that and I don't know what I should use as a default virtual host to address my machine by IP. I have tried moving the ReadyNAS web interface to a sub-folder of the Apache Root, but that seems to break the web interface also.
It should be noted, that while I could create a subdomain for the web interface, I would rather address it by my machine's local IP only so it isn't visible to the outside world. While there are some simple tutorials of setting up a website on the ReadyNAS they use the ReadyNAS share system that appends a folder name to your url i.e. domain.com/www/. This is just no good.
Long story short, I want to host my website using my domain on my ReadyNAS (no sub-folders). I want to continue using the ReadyNAS web interface, but only from my local network. I do NOT want to run a second web server. I do NOT want to wipe the original OS (proprietary hardware/drivers are used for intelligent power management)
For reference it is a ReadyNAS Ultra 4+ with ReadyNAS default OS (Debian Etch).
P.S. Don't tell me this isn't what a NAS is for, I am aware and I don't care nor want to hear you cry about it.

If I did understand correctly you would like to access your own site with address like mydomain.home not mydomain.home/www I have achieved this with following config by using ReadyNas Duo
First modify Virtual.conf file from
<VirtualHost _default_:80>
to
NameVirtualHost *:80
<VirtualHost *:80>
Now you can add new virtual host config file under the addons directory ie. mydomain.conf
<VirtualHost *:80>
ServerName mydomain.home
DocumentRoot /var/www/mydomain.home
<Directory /var/www/mydomain.home>
Options Indexed
Order allow,deny
Allow from all
</Directory>
SSLEngine off
</VirtualHost>
Here is link for the original post that I did follow https://liewdaryl.wordpress.com/page/2/
I did add NameVirtualHost definition so apache would not warn about overlapping virtualhost definitions

Related

Deploy Admin panel for my site on the same IP using Apache 2

I'm a newbie in deploying apps using Apache. Not so long ago I've deployed vue.js using very simple tutorial configuration and then I tried to deploy strapi admin panel on the same VDS using same IP. So I am faced with a couple of troubles:
I don't know how to modify my configuration to deploy admin panel with my site correctly.
here is my config:
<VirtualHost 188.***.**.***:80>
ServerName my-site.com
ServerAlias www.my-site.com
ServerAdmin someEmail#example.com
DocumentRoot /var/www/mySite/public_html
<Directory /var/www/mySite/public_html>
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/www/mySite/error.log
CustomLog /var/www/mySite/access.log combined
</VirtualHost>
I've rented VDS on hosting service and they gave to me technical hostname which is connected with my server IP and this makes me puzzled, because I have to configure Server name and Server Alias in my site conf. Is these parameters will be visible in internet or in domain name system?
maybe I'm asking stupid questions but after a week of deep-sitting in documentation I didn't find clear answer.
Well, i found an answer. If you faced with the same problem. To deploy another site on your apache server you should add another Virtual host directive in your conf file (example in question), then when you try to set Server name or Server Alias - you should write your website domain. Just look at apache as phone list for all websites of your server. Domain names is always connected with some ip address so when you write down web site url DNS looking for ip address wich is connected with domain you wrote, and after that apache - wich works on server try to compare your domain with domain in confs - if it find equals it will throw back to you webpage if not it throw to you first deployed site (first Virtual Host to say simple).
Lets come back to the main topic. if you want to have two sites on your VDS - you have to have two domains in that case it is very easy to deploy two sites on the one server with one ip. i hope my answer will be useful for newbies. And i really sorry for my english.

Host multiple domains with apache

I'm trying to set up an ubuntu server to act as a dns server and host a simple webpage, some git repos, and some software for issue tracking, code review, and the like. I settled on Phabricator as the issue tracking/ code review software of choice, since it seemed to be a good all-in-one solution. I've got my server hosting my webpage and git repos, so that part seems to be working ok. Now here's the issue I've run into (from Phabricator configuration instructions):
If you haven't already, set up a domain name to point to the host you're installing on. You can either install Phabricator on a subdomain (like phabricator.example.com) or an entire domain, but you can not install it in some subdirectory of an existing website
I have no idea where to even begin setting up another domain name on my server. How do I set up a second domain name for Phabricator to use?
I see a lot of guides online that say to modify resolv.conf to add a dns entry, however mine looks like this:
Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 192.168.1.1
and I'm not sure what I should change to get dns entries to show up here.
I'm assuming you have only one IP address, which means you should be using virtual name-based hosting. There are a number of tutorials for doing this, but in short:
Create a virtual host configuration file in:
/etc/apache2/sites-available
For example:
nano /etc/apache2/sites-available/phabricator
Run:
a2ensite phabricator (in this example, but use the configuration file name you used above)
apache2ctl restart
The configuration file (which can be named whatever you'd like) needs to contain a number of items. A simple example would look like this:
<VirtualHost *:80>
DocumentRoot /www/example1
ServerName www.example.com
</VirtualHost>
DocumentRoot is the full path to the root of your site, usually where index.html, index.php, or the like is located. The default is /var/www. You could put somethig like /home/phabricator or /var/www/phabricator, but make sure you install Phabricator in the directory you specify.
ServerName is the full FQDN of your site, such as "www.google.com" or "phabricator.yourdomain.com" or even "phabricator.local". Basically it's the same value as you have set in your DNS for your A record, or in your /etc/hosts file. If you don't know about /etc/hosts, then disregard that part.
You'll probably need a few more directives in your configuration file, but you can find what's available on Google. I would suggest following some tutorials to get your configuraiton right.
But overall, you just need to create a virtual host config file, enable it, then restart the server, which is what the above instructions do. Apache will respond to the web request based on the site you put into your address bar.
P.S. Just noticed your DNS part of the question. Do you have DNS set up publicly to point a domain (example.com) or subdomain (something.example.com) to your server's IP address?

Name based virtual hosts

I'm having trouble figuring out how virtual hosting works. For example lets say in my 'hosts' file I have:
127.0.0.1 localhost
127.0.0.1 mysite1.com mysite1.com mysite3.com
Does this mean that whenever I type in localhost, mysite1.com, mysite2.com, or mysite3.com into my browser URL, the page loaded will be the same for all of them?
The /etc/hosts file only has limited connection to virtual hosting of Apache. The only thing you do with it is give your host (or rather the loop back interace lo) several names. If you haven't set up anything about virtual hosting yet (which I assume) typing
http://localhost/
http://mysite1.com/
http://mysite2.com/
http://mysite3.com/
as URL in your browser will all render the same welcome page (provided you have at least set up your Apache) because in all cases the browser will try to access the web server at 127.0.0.1 which your Apache usually listens to.
To create a true virtual hosting you now need to activate this feature in the configuration file of Apache using the tags
<VirtualHost mysite1.com:80>
...
</VirtualHost>
<VirtualHost mysite2.com:80>
...
</VirtualHost>
<VirtualHost mysite3.com:80>
...
</VirtualHost>
The simplest version of a virtual hosting would be that you define a seperate document root for each host and share all other configuration items. The details of this (represented by the ...), of course, would definitely be out of scope of this answer. A good start for reading would be http://httpd.apache.org/docs/2.2/vhosts/examples.html.

Define local site in Apache - Use port other than 80

I'm wondering if anyone can help me define a new local VirtualHost using Apache.
The goal is to have a site that is viewable only from the local network (hidden behind a firewall). Right now I have Webmin installed and it runs on transaction:10000. I am trying to get the other site running on transaction:7000.
The following does not work:
DocumentRoot /var/path
Is there a better way to do this? I'm new to Apache and trying to figure this out.
Summary: Need local /var/path directory to run on a port other than 80 for local access only.
I'm assuming that you don't know to Apache Virtual Host Code. I will show you how to use it. If this didn't help you please don't hesitate to reply to me.
You must place code in your HTTPD.CONF which can be found in the conf folder. If your file is called wwwroot instead just change the name in the code below BUT DO NOT CHANGE THE NAME OF THE FOLDER!!!
NameVirtualHost 111.22.33.44
<VirtualHost *:7000>
ServerName www.domain.tld
ServerPath /domain
DocumentRoot /htdocs/domain
</VirtualHost>
What does this mean? It means that a request for any URI beginning with "/domain" will be served from the virtual host www.domain.tld. This means that the pages can be accessed as domain.tld/domain/ for all clients, although clients sending a Host: header can also access it as domain.tld/.
In order to make this work, put a link on your primary virtual host's page to http://www.domain.tld/domain/. Then, in the virtual host's pages, be sure to use either purely relative links (e.g., "file.html" or "../icons/image.gif") or links containing the prefacing /domain/ (e.g., "http://www.domain.tld/domain/misc/file.html" or "/domain/misc/file.html").
So all domains will be pointed to your IP address and based on the domain name if it is "www.domain.tld" it will take you to the folder "/htdocs/domain" or "/wwwroot/domain"
EDIT:
<Directory "/var/path/">
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Directory>
This lets access to the "/var/path/" folder from only localhost which is where Apache is configured which is on your computer!
Good Luck!!!

How to setup sub-domains like blogspot

What should do to setup a sub-domain for the users when they sign-up into my site.
What are the infrastructure required? I am using Linux servers.
You can either use a specific DNS (CNAME or A/AAAA) entry for each known subdomain, or a wild-card DNS entry that'll accept *.example.com:
$ORIGIN example.com
foo IN A 12.34.6.78
bar IN A 12.34.6.78
or
$ORIGIN example.com
* IN A 12.34.6.78
The advantage of this latter is that no changes are required to either DNS or Apache configuration once the service is running. The disadvantage is that all such wildcard lookups must (by definition) end up returning the same IP address.
The Apache configuration will depend on your requirements, both for end-user control and security. Note that if the users have permission to run CGI scripts on the server then additional setup will be needed to ensure that that's done securely.
Depending on whether content is static or dynamic this will also affect your configuration:
Use mod_vhost_alias to map individual virtual hosts into their individual directories on the server.
If you really want, create a separate <VirtualHost> section for each known site, but then you'll have to restart Apache each time a new user signs up
Use a single <VirtualHost> and then look at the hostname part of the requested URL (from the $SERVER_NAME environment variable) in the scripts that render the output to figure out which user's content to display.
You can make a CNAME entry/ A Record in your DNS settings, for each subdomain
A CNAME record is a record in your
Domain Management Settings that allows
you to control a subdomain of your
domain.
To automate it along with registration, you can write a script which is executed for each user, when s/he registers.
You can refer to this link, as well, for a step-by-step process for Apache:
How to setup subdomains in apache
(since you mentioned Linux, I assume it must be APache. Please mention if it is otherwise)
Alternate Solution
You can also refer to the wildcard solution, given by Alnitak, in the same thread. I find his is an easier way. :)
infrastructure includes access the the dns server to add a wildcard entry, and rewrite rules in Apache.
Try these answers:
How to let PHP to create subdomain automatically for each user?
How to make subdomain user accounts in a webapp
or this link:
http://jam.jrox.com/docs/index.php?article=76
If your using Linux server's I'm assuming your using Apache as your webserver.
You'll have to setup proper DNS routing for the sub domain as well as a virtual host.
Virtual Hosts are fairly easy to setup but I'm not sure how easy it is to do them on the fly progmatically.
Most of the time it's as easy as editing your apache config file and adding the following:
Port 80
ServerName www.mydomain.com
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /www/user-bob
ServerName bob.mydomain.com
...
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /www/user-sally
ServerName sally.mydomain.com
...
</VirtualHost>
The VirtualHost Documention will probably of some use to you.
Apache allows you to specify any number of 'sites' based on subdomains on a single server. Creating a new 'site definition' file with the appropriate subdomain information in it, along with proper DNS wildcards, will do what you want.
In other words, the process is like this:
Setup wildcards so that *.mysite.com directs to the proper server.
When a new user signs up, create the proper Apache site definition file - you'll probably have a base template that you put the right subdomain information into and save.
Make Apache re-read its configuration.
Profit.
IMPORTANT This is based on a Debian-style Apache configuration, where the config files are included in a directory, and the main configuration reads all the config files in that directory. This will simplify things a great deal, because adding/removing subdomains will mean adding/removing files, rather than editing a single file, and so the process will be much easier to automate.