2

I have a 2 core, 2 GB RAM VPS with a dedicated IP address from Digital Ocean for my project. I'm using nginx as a webserver, MySQL as a database server and bind as a DNS server.

My project is a free hosting platform for educational purposes. I'll be teaching PHP and MySQL to students from my neighborhood and I want them to practice on their own subdomain with a PHP and MySQL support.

For example, if my main domain name is example.com, I'll also setup a wildcard SSL for my domain, and student subdomains should be like student1.example.com.

Students will be able to activate their web space with the subdomain they choose automatically using my setup script which is written in PHP.

How can I achieve what I want without using any web administration control panels? How can any subdomain which is choosen by a student resolve my main domain?

Can students use their own TLD domain on a setup like this?

Do you have any suggestions for this kind of setup?

1 Answer 1

2

Not much configuration is required.

First, you set up your domain using a wildcard record like:

*.example.com 300 IN A MY.IP.AD.DR

Then you set up Nginx to match on a regex server name from which you can serve a different folder depending on the user name.

server {
  listen 80;
  listen 443 ssl;

  server_name ~ ^(?<user>.+)\.example\.com$;

  ssl_certificate /path/to/cert;
  ssl_certificate_key /path/to/key;

  location / {
    # Set root directory depending on the domain name.
    root /var/www/$user;

    # Try to serve the file before calling PHP.
    try_files $uri $uri/ @proxy;
  }

  location @proxy {
    fastcgi_pass PHP.FPM.AD.DR:PORT;
  }
}

Note however that you will need a wildcard SSL certificate for it to be valid whatever the targeted domain name is.

2
  • nginx configuration ok. dns configuration?
    – Murat SAÇ
    May 24, 2014 at 16:36
  • 1
    @muratsac using your DNS provider's interface, you can set up your DNS zone using wildcards as shown.
    – Spack
    May 24, 2014 at 18:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .