Subdomain on Ngix duplicating Main site

August 2, 2015 1.7k views
Nginx DigitalOcean

Hey all,

I've followed this tutorial:


On how to set up a server block. My main site is running fine, but when I try to navigate to my test site I keep getting the main site rather than the test site. I've of course configured my document root to the test folder's root. In my DNS I created an @ record and pointed to the IP.

For some reason no matter what I do it keeps giving me the main site even though i'm not pointing to my main site's root. Any ideas? @asb

This guy had the same problem but his solution didn't work for me:

  • Try creating separate server files inside the directory:


    Also do not forget to enable your new site by creating new symlink:

    sudo ln -s /etc/nginx/sites-available/newsite /etc/nginx/sites-enabled/

    Hope this helps!

  • Thanks @saurabh I went through a dozen or more tutorials and request postings like this one and I followed all the instructions exactly including what you suggested. No luck.

  • If you follow this tutorial, I hope your root directive in both the server blocks, is not pointing to the same directory:

    root /var/www/;
8 Answers

have you created different nginx and php-fpm conf file configure it
it ll work

Hey @karankotak94 yes my test site and main site have different config files. What do you mean by the php-fpm config file? Can you explain this a bit more please?

hiii @larrywilliamsjr ,
/etc/php-fpm.d/default.conf this file will be there you have to copy it to /etc/php-fpm.d/yoursite.conf
change listen = to
listen =

in nginx conf file
# pass the PHP scripts to FastCGI server listening on

    location ~ \.php$ {
    root           /your root path;###this is also impotent may cause error so be carefull
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
    include        fastcgi_params;

change to

and after this also it wont work then go to /var/log/nginx/error.log nd post errors

@karankotak94 thank you for the well thought out answer. A couple things to note here:

I don't have a /etc/php-fpm.d/default.conf.

This is what I do have:

drwxr-xr-x 4 root root 4096 Jul 17 23:42 ./
drwxr-xr-x 5 root root 4096 Jul 19 22:14 ../
drwxr-xr-x 2 root root 4096 Jul 19 22:16 conf.d/
-rw-r--r-- 1 root root 4555 Apr 17 07:57 php-fpm.conf
-rw-r--r-- 1 root root 69890 Jun 1 02:22 php.ini
drwxr-xr-x 2 root root 4096 Jul 17 23:42 pool.d/

None of the listed files have listen = and if they do it's commented out.

Secondly, just be clear, should I have two nginx.conf files? I only ask because none of the tutorials that i've read directed me to duplicate this file. If I did what would I name the second nginx.conf file? By the way thanks for bringing these issues up as no other tutorial has mentioned fpm.

ok @larrywilliamsjr
lets start from the beginning
the site which is working ( eg. )
you have to create same site for testing ( eg. )

now go to cd /etc/nginx/conf.d/main.conf or where ever is your main site conf file is
cp main.conf sub.conf
chmod 755 sub.conf
copy the path where is your all files are located ( eg. html/main/)
vi sub.conf
server name
root {files pathe }
location / {
root path;
index index.php index.html index.htm;
(this path will be in comment so copy this and past it )
location ~ .php$ {
root file path;
index index.php;
fastcgiparam SCRIPTFILENAME $documentroot$fastcgiscriptname;
include fastcgi
uncomment this
location ~ /.ht {
deny all;
now where ever is your php-fpm.conf file is find it
i use to keep it /etc/php-fpm.d/*.conf
cp www.conf sub.conf
chmod 755 sub.conf
vi sub.conf
listen =

since you have created hosting account for your site which the name server pointed on main site...(
so it will work if not then we ll find another better way.
{for any server or hosting you can visit}

Hey @karankotak94 thanks for the detailed reply. This last section is a little unclear to me:


cp www.conf sub.conf
chmod 755 sub.conf
vi sub.conf
listen =

What are you telling me to do here? Copy my fpm file and name it something different, then change that line?

hiii @larrywilliamsjr
yes copy your php-fpm file give same name as your site name is
there you will find all this stuff

Have another answer? Share your knowledge.