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

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

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

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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