0

i setup a virtualbox with a clean install of ubuntu 16. installed nginx, php7, mysql all fine. the computer name is: mercury

i've setup a folder that would be the root for all my web projects: /var/www

i want to be able to have a dynamic virtual host where i can just create a folder (like: /var/www/project1) and i'll easily be able to access it via the browser at: project1.mercury

i can i achieve this? in my browser: mercury/ loads up fine (/var/www/index.html), but as soon as I use a subdomain it craps out and gives me a dns error: server DNS address could not be found

here is my: /etc/nginx/nginx.conf file

user www-data;
worker_processes 4;
pid /var/run/nginx.pid;
worker_rlimit_nofile 30000;

events { worker_connections 1024; }

http {
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        server_tokens off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;
        proxy_connect_timeout 60;
        proxy_read_timeout 60;
        proxy_send_timeout 60;


        gzip on;
        gzip_disable "msie6";
        gzip_types text/plain text/xml text/css text/comma-separated-values;
        upstream app_server {
            server 127.0.0.1:8080 fail_timeout=0;
        }

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

/etc/nginx/sites-enabled/default:

server {
    listen 80;
    server_name  ~^(?P<subdomain>.+)\.mercury$;
    location / {
         root /var/www/$subdomain;
    }
}

UPDATE:

so this config works, but i need to manually update my Windows hosts file and specify the subdomain with the same ip address:

192.168.1.101 project1.mercury

if i dont, i get a dns error.

how can this be achieved without having to manually add an entry in the hosts file everytime??

Ourx
  • 109
  • 3
  • 15
  • Try this http://stackoverflow.com/questions/138162/wildcards-in-a-windows-hosts-file , You will need a local DNS to help you resolve all *.mercury to your localhost. – Hammer May 30 '16 at 06:07
  • is it possible to setup a wildcard entry in my router (i have a tp link td-w8968 router) as this is my dns server? – Ourx May 31 '16 at 20:41
  • @Qurx If your router supports 3rd party firmwares like dd-wrt, you may achieve that by using built-in local DNS services like Dnsmasq. However, TP-LINK td-w896 doesn't seem to be supported by dd-wrt. – Hammer Jun 01 '16 at 02:13

0 Answers0