Handling subdomains / NGINX configuration

What I’m trying to do: Install WordPress & NextCloud to different drive (not directory)

Where I’m stuck: Understanding NGinx basics and how to…

What I’ve already tried: Regular installation

Hello and kind regards.

First of all I would like to annotate that I am not a native speaker, so please excuse any strange expression. Thanks in advance.

Many years ago I fiddled around with Apache but I changed to NGinx in order to use it on my Raspberry Pi for some light WordPress development and private cloud services with NextCloud. I am a Mac user since years, never been into console too deep so Linux commands and else are somewhat familiar but not very well known to me.

Right now NGinx is running on my Raspberry Pi in non-Docker installation providing a WordPress site off the standard Bookworm Linux OS on the main drive of the Pi. The main drive is one of 4 SSDs. What I want to achieve (and where I get stuck sooner or later…): I want to keep the NGinx server on the main (boot) drive but the WordPress installation onto the second SSD and the NextCloud installation on the third SSD (note: NextCloud is NOT installed by now).

What I understood by now (please correct if I am wrong somewhere): NGinx handles sites / domains via the “sites-available” directory configured via nginx.conf while the site (WordPress or else) is located in the regular /var/www/html directory.

Now, what I want to achieve is NGinx handling the WordPress installation from a different drive (second SSD) on top level, so to say “/” of that second SSD, the same with NextCloud configured as subdomain to NGinx on the top level “/” of the third SSD. NextCloud will make use of it’s own MariaDB database, of course (if I`m getting all this to work somehow).

I do not really understand the dependencies of nginx.conf and the “sites-available” / “sites-enabled” or where to edit what file to achieve what I am planning. As far as I understood NGinx by now it should be possible to sym-link any domain or subdomain to the “sites-enabled” directory but I do not get the connection to the physical installation location and that “sites-enabled” directory.

I know how to edit via console / SSH in general but I really could need some help in this as I am more of the lazy design Mac user type than the code editor (but I try to learn, I like to understand things!). Please have in mind I am not the youngest one anymore (late 50s…), it takes some time for me to understand complex things like NGinx (I am much better at WordPress…).

Thanks for any helpful hint in advance!

Jens

Hey @Jenne! Let me preface my answer by saying that I am not a Raspberry Pi expert, nor a WordPress/NextCloud expert, and that we do not officially support running NGINX on a Raspberry Pi. The NGINX package you installed is provided by Debian and in turn pulled in by Raspbian OS. With that being said, lets see if I can help you :slight_smile:

A few thoughts:

  1. There is a Wordpress NGINX setup guide that you will hopefully find useful Nginx – Advanced Administration Handbook | Developer.WordPress.org, there is also a Digital Ocean guide that covers a simple Wordpress setup here Install WordPress with Nginx on Ubuntu 18.04 | DigitalOcean
  2. Since you have multiple SSDs, are you sure you can reach the other SSDs from within your primary/NGINX SSD? This is critical for NGINX to be able to serve your Wordpress deployment.
  3. The “sites-available/sites-enabled” directory is an Apache convention that the NGINX packages built by Debian have adopted. It is the convention used by the guides I shared above, which might make things easier for the time being. However, I’ll advise that you can easily simplify your config into something much simpler. I would recommend pulling the NGINX Docker image and looking at both /etc/nginx/nginx.conf and /etc/nginx/conf.d/default.conf to see a very simple NGINX config in action. You should hopefully be able to adapt it to your needs.
1 Like

Hello Alessandro and thank You very much for Your reply!

First of all: I knew that NGinx on RaspBerry is not officially supported nevertheless it seems to become more and more popular. Sorry not for mentioning it more clearly but I installed NGinx already and WordPress (and MariaDB and PHP 8.4 & 8.5 modules, PHPmyAdmin, connected via No-IP and even running as HTTPS), too. Works like a charme on that little RaspBerry Pi 5 16 GB RAM. I am pretty sure it can handle the load of small up to medium web sites based on WordPress (and in fact I will never get such load at all so this is ok to me). So right now everything is working within standard configuration. I thought about that Docker-way but some aspects don’t fit my future needs so I intend to keep it the way it is by now. Helps me a bit to understand Linux basics a little better.

The four SSDs are connected to the only PCI 2.0 lane of the RaspBerry so strictly physically spoken they are adressable from within Raspian Linux Bookworm. They are bound to that OS by making use of the “/mnt/” directory. I am already running a SFTP server on that little box which addresses the fourth of the SSDs as storage space so I think all the others should be “reachable”, too. In fact this fourth SSD works as backup location for my major WordPress site at https://derstreuner.ch (not self-hosted). The backup WordPress plugin over there uses that fourth SSD as online backup location without any troubles. No worries, You can switch to other languages :wink:

Why that “installation on dedicated SSD” at all? Though it might appear not very effective I stick to my old rule in making drive backups to dedicated drives and not directories within operating system locations. Makes it sometimes easier to restore contents when using new machines (never made use of virtual hosts before in any way). I once ran a static site on a Macintosh Plus with 4 MB RAM and a SCSI to Ethernet converter (very strange little box…), a static site on an Apple Network Server 500 (that odd box that used that “AIX” OS not made by Apple) and even a replica of the first website ever from T. B. Lee at CERN in Geneva on a NextCube. All my experiences during work at these little more or less fun projects led me to my “dedicated drive installation location” directive. Hope You don’t mind…

As far as I understand NGinx by now it should “reach” the other SSDs, to be more exact: Their mount point within the /mnt/ directory as these are handled like standard directories within RaspBerry Pi OS. So my conclusion is: Leaving the basic configuration of NGinx (and PHP and MariaDB) on that first SSD utilizing the /var/www/html directory of RaspBerry OS as it is installed by default should make it possible to sym-link. To be even more exact: As I have been reading through several handbooks, man`s, online posts and else before I noticed it would be the best to keep NGinx installations (and PHP and MariaDB and else) there where they are supposed to be within the OS used. Otherwise even more confusion and work would be appearing (and I am getting too old for that by now…).

As far as I understand Linux by now this would mean I will have to change the basic installation directory of WordPress and NextCloud to the top level of any dedicated SSD and sym-link the according / resulting installation to the “default” file located within the “sites-available” of NGinx. Am I right in this? I don’t wanna brick my already working WordPress installation…

The SSDs always get the same mount point on re-boot as their dedicated mount point to the OS is defined by their unique UUID, so this shouldn’t cause any troubles (and in fact this works on the SFTP-side without any troubles until now).

Depending on if my conclusion is right the question would be how to sym-link the installations of WordPress and NextCloud (this one supposed to run as sub-domain managed by NGinx) to NGinx itself, to what / which file located where. This is where I get stuck even if reading the documentations provided by You. I am not the fastest learner (anymore) but I am not afraid reading tons of lines even if it is just for more or less fun :wink:

Once again: Thank You very much!

Jens

2 Likes

Hey again! So, if you can reach everything just fine via the /mnt directory, you might not need to symlink any files. The simple/ideal solution would be for you to serve your WordPress files from the /mnt directory. Instead of symlinking any files, create a new NGINX config file per the examples in the guides I shared earlier and wherever you see they reference the WordPress files (e.g. the root directive), go ahead and replace it with something like root /mnt/<ssd path>/<path to wordpress files>;. Does that help?

Again hello and thank You so much!

Exactly this is where my brain gets stucked (thanks for guiding without knowing that in between ears thing!).

Following Your advice this would mean to solely edit the nginx.conf to make use of the top level of one dedicated SSD as new root html directory instead of the regular within the RaspBerry Pi OS. Am I right? But what about the sub-domain located on a different drive for NextCloud (or other services)?

Jens

I truly do not know how NextCloud works, but assuming it has its own set of html/php files, you should be able to do something similar to what you are doing with WordPress. You would want to use two different server blocks. One for WordPress deployment and one for your NextCloud environment/subdomain.

As long as your routes are correctly configured (via your IP config/DNS/hostnames/etc…) you should be able to configure multiple subdomains/deployments/environments/etc… within a single NGINX deployment.