Question

Subdomain on Ngix duplicating Main site

Hey all,

I’ve followed this tutorial:

(https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-14-04-lts/)

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:

https://www.digitalocean.com/community/questions/how-to-setup-subdomain-on-nginx-server

Subscribe
Share

This comment has been deleted

This comment has been deleted

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/test.com/html;

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.

Try creating separate server files inside the directory:

/etc/nginx/sites-available/

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!


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

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

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 i [sub] . . listen = 127.0.0.1:9002

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

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

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 cd copy the path where is your all files are located ( eg. html/main/) vi sub.conf i server name sub.com www.sub.com 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; fastcgi_pass 127.0.0.1:9002; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } . . 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 i [sub] . . listen = 127.0.0.1:9002 …

since you have created hosting account for your sub.com site which the name server pointed on main site…(ns.main.com) so it will work if not then we ll find another better way. {for any server or hosting you can visit http://www.invanos.com/manage/cart.php} visit http://www.rackspace.com/knowledge_center/article/installing-nginx-and-php-fpm-setup-for-nginx

@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/ root@MYServer:/etc/php5/fpm#

None of the listed files have listen = 127.0.0.1:9001 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.

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 = 127.0.0.1:9000 to listen = 127.0.0.1:9001

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

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

} change to fastcgi_pass 127.0.0.1:9001;

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

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?

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

This comment has been deleted