I have a LEMP stack running with WP on the main domain, however, I have another PHP app as a subdomain e.g. domain.com/subdomain the issue I’m having is when I try to navigate around on the app on subdomain I get redirected to the main domain which is WP.

Do I need to modify my Nginx config to achieve subdomains?

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.

×
1 answer

Hi @Yizi,

Yes, you’ll need to create another Nginx config for every domain.

How Nginx works is you add as many configuration files for your domain as you want. If you have 5 domains on your droplet, then you have a configuration file for every one of them.

If you are unsure how to proceed with doing so I’ll recommend checking the following article:

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

When using the Nginx web server, server blocks (similar to the virtual hosts in Apache) can be used to encapsulate configuration details and host more than one domain off of a single server.

In this guide, you’ll discuss how to configure server blocks in Nginx on a server.

Regards,
KFSYs

by Justin Ellingwood
When using the Nginx web server, server blocks (similar to the virtual hosts in Apache) can be used to encapsulate configuration details and host more than one domain off of a single server. In this guide, we'll discuss how to configure server blocks in Nginx on an Ubuntu...
Submit an Answer