domain mapping: php or nodejs & nginx - php

I want to automate a process so that my clients can sign up on their own to my application, insert them own domain name and i can map the domain name to their subdomain.
For example, they have a subdomain called mappable.example.com and they have a domain name called mappable.com
I have two questions:
1. How do you create a subdomain for them in php and/or nodejs called mappable.example.com
2. How do you map the domain name to mappable.com
I'm using nginx as a web server. Do I have to use php or nodejs to manually edit the nginx config files?

I'm assuming you own example.com, they own mappable.com, and you want to allow them to use their domain mappable.com to access your subdomain mappable.example.com hosted on your server.
There are a few steps you'll need to do for this.
Set up wildcard DNS with your domain registrar so that all sub-domains will come to your one server.
Set up wildcard domain handling in nginx's conf on your one server so that all requests are sent to your code. You can do this using an underscore as the server name to make it the default server.
In your PHP code, you can check the headers to determine what domain the request is coming in through. Do a dump of $_SERVER to see what's in there. You will then know if the request came to mappable.com, mappable.example.com, etc...
Once you are in PHP with the domain or subdomain that was requested, you can act accordingly. You'll want to store the mapping of domain to subdomain in a database most likely. Additionally, you'll have to tell your users that they need to set up a cname, for example a cname of "mappable.com" to "mappable.example.com".
I think that should do what you need.

Related

Symfony2 routing domain virtual host

I haven't found any solution to my problem with symfony and virtual hosts.
I have one website www.example.com and have routes that have different contents based on an id.
Example:
www.example.com/id/1 is one website with menus that point to subpages:
www.example.com/id/1/page1
www.example.com/id/1/page2
www.example.com/id/1/page3
what I want is to set a new domain that points to this website with id 1 and another domain that points to id 2, etc.
For example:
www.newdomain.com shows content from www.example/id/1
www.newdomain.com/page1 shows content from www.example/id/1/page1
www.newdomain.com/page2 shows content from www.example/id/1/page2
www.differentdomain.com shows content from www.example/id/2
www.differentdomain.com/page1 shows content from www.example/id/2/page1
...
First of all, you just have to point both virtual host configurations to the same folder to make both URLs work.
But the virtual host setting is just one side of the configuration. You won't be able to configure the actual behaviour of the application regarding the different incoming URLs. I don't know if this can also be achieved via .htaccess settings, but you can definitely check in the controller of your application from what URL the request was send and then forward the user accordingly.

How to have different /servers with same Domain?

I have a website foo.com on wordpress and I want to do this foo.com/mexico, foo.com/venezuela, delivery different /server for each city with the same domain (without wordpress multisite).
I'm not asking about to detect ip by city but server and/or domain/dns configuration to do that.
I know there is other ways to accomplish this, but want to know about this one.
Here is an example:
http://www.vice.com/pt_br
http://www.vice.com/es_co
EDIT SOLUTION
This was my solution:
Create a subdomain, example.foo.com pointing to another server.
Create a folder on the main server with the name i wanted for the
link, for example 'mexico'
Inside this folder created a .htaccess:
RewriteEngine ON
RewriteCond %{REQUEST_URI} ^/mexico
RewriteRule ^(.*)$ http:// example. foo. com/$1 [R=301,L,P
This works for me. If i want another /server i just repeat with another name, example 'venezuela'. The subdomain name will be hide by the .htaccess and this 'example.foo.com' will look like this 'foo.com/venezuela'.
What you are describing is a reverse proxy.
You can set it up using apache's extension mod_proxy. Personally I haven't touched that, but my opinionated answer would be to suggest you have a look at nginx. It's a dead simple reverse proxy. You can easily run nginx in front of apache, intercepting requests and passing them on to different servers or just send html-files directly.
A nginx-config can be as simple as:
server {
listen 80;
server_name example.org www.example.org;
location /mexico/ {
# We could have an apache server running on another port...
proxy_pass http://127.0.0.1:8000;
}
location /venezuela/ {
proxy_pass http://123.123.123.123:8000; # ...or another server.
}
location /bulgaria/ {
# Or just serve some static files
# In apache, do you set up a virtual host for this? christ.
root /var/www/static_html;
# If static html is all you have, what is apache even doing
# on your server? Uninstall it already! (As I said; opionated!)
}
}
edit: Finding my own answer after a few years, I'd just like to add that the 301-rewrite rule that OP choose to go with adds another request that the browser must wait for before getting redirected to the real address. 301-requests are still to this day considered bad SEO, and adds some (usually minor) loading time.
You will need to use subdomains, and set the A records at your domain registrar to map each subdomain to the different servers.
Here is a related SO question. Note, it was closed, but the selected answer is what your going for: Subdomain on different host
one.yourdomain.com --> points to ServerA
two.yourdomain.com --> points to ServerB
There is info on GoDaddy's site too. If your not using GoDaddy, the process would be similar: https://support.godaddy.com/help/article/4080/managing-a-domain-names-subdomains
You go into your domain registrar where you can edit your domain settings. It will probably be in something about DNS. Your wanting to add a new "A Record".
Some registrars simply let you put in "yoursubdomain", the IP of the server, and the TTL (Time To Live).
So enter your the subdomain for your first one, the IP of the server you want it to point to, and the TTL (if it asks) which is usually 3600.
Then add another "A Record", only for your other subdomain, the IP for that server, and TTL.
Repeat for however many subdomains and servers you need.
your solutions is:
1.You can use A record & subdomains for every server.
2.You can use your webserver configuration to relay user to destination servers (Apache,NGINX & etc)
But here I see you'r asking about Wordpress from multi server. You can only have multi server for your static contents (CDN), but your database must be in one place except you want to use cloud DB.

Redirect domain to a directory on another domain

I have bought a domain and I want to redirect it to a directory on another subdomain.
Exemple:
A user type www.firstweb.com in the URL bar and he has to be redirected to www.secondweb.com/directory/ but the URL shown has to be www.firstweb.com without iframe.
Other exemple:
www.firstweb.com/contact/ shows the content of www.secondweb.com/directory/contact.php but the URL shown has to be www.firstweb.com/contact/ even after the redirect.
Both domain and servers are hosted by the same company (OVH).
I don't know if it is understandable but I dont know how to figure it out.
Thanks a lot for your help.
J.ROX
You can do this by installing NGINX (http://nginx.org/) on the webserver. Then you can check from which base URL the user is coming from, and return the appropriate content. This is also possible with an Apache server using Virtual Domain Names.
Or you can setup your DNS correctly, this can be done by your domain provider.

Code igniter native session namespace

https://github.com/appleboy/CodeIgniter-Native-Session/blob/master/libraries/Session.php
If you run multiple applications on the same site, please modify your_application/config/session.php file line:
// Session namespace
$config['sess_namespace'] = 'your_application_name';
In my setup I run the same application across different sub domains. Does this apply to me? Or is this for multiple applications running on same domain?
It depends on what you have in $config['cookie_domain'].
By default (if you don't specify), php will set the domain to the domain of the current request meaning that the session cookie created for domain.com will be sent to the www.domain.com and every other higher level subdomains too (see the $domain parameter).
If you are using the "main" domain (one segment + tld, ie.: domain.com) you might need to redirect the traffic to a subdomain (like www) before you set any cookies, or you can of course use the sess_namespace setting.

changing my ip based url to name based url

basically i have my website under 91.xx.xx.76/mywebsite in folder /var/www/mywebsite
and i want the user to type www.mywebsite.com, i have search some methods in doing so but doesn't actually solve it. they say to create a file under sites-available then enabled it
i have created file under sites-available and also enabled it using a2ensite mywebsite, then restarted apache2 using service apache2 restart then i try to load www.website.com but it loads nothing..
any help?
thanks
To use "name based URLs", you need to register the domain you wish to use in the global Domain Name System (DNS). Just setting some configuration in your own server is not enough; anybody could do that, which means there could be any number of people claiming the domain www.website.com at the same time. That's not how it works.
Find yourself a domain name registrar whom you'll wire a small amount of money in exchange for registering your desired domain. This purchases you the rights to set the DNS configuration of said domain to point its A record to your server's IP address.* This is what enables you to resolve www.website.com to your server. Then you only need to configure your server appropriately to serve requests for www.website.com.
* More correctly, it purchases you the right to set the NS record of the domain to point to a name server you control on which you can set any number of DNS records you want, including the A record. Most registrars also offer a name server as part of the deal of purchasing a domain, but those are actually separate things.

Categories