Question

I have an A Name domain setup on Nginx, I also have wildcard DNS setup on Digital Ocean.

I would like my main domain to point to where it is: /usr/share/nginx/html/mission13.io

I would then like all the wildcard domains to point to their respective folders:

  • /usr/share/nginx/html/sub1.mission13.io
  • /usr/share/nginx/html/sub2.mission13.io
  • /usr/share/nginx/html/sub3.mission13.io

Here is what I have, but I am not sure what to do to get them to point to the proper location. What can I change to do that?

server{
    listen 80;
    root /usr/share/nginx/html/mission13.io;
    index index.php index.html index.htm;

    server_name mission13.io www.mission13.io *.mission13.io;

    location / {
            try_files $uri $uri/ /index.html;
    }
    include /usr/share/nginx/conf/mission13.io.conf;
    location ~ \.php$ {
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
    }
}
Was it helpful?

Solution

Another way please change server name to _ then it will search folder with the host name inside root /usr/share/nginx/html/ directory.so,your directory looks clean

server{
 listen 80;
 root /usr/share/nginx/html;
 index index.php index.html index.htm;

 server_name _;

 location / {
        try_files $uri $uri/ /index.html;
 }
 include /usr/share/nginx/conf/mission13.io.conf;
 location ~ \.php$ {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
 }
}

OTHER TIPS

Got it!

I need to use $http_host like so:

root /usr/share/nginx/html/$http_host;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top