Hosting YOURLS and NextCloud with Nginx?
I have a new server set up, and finally got a LEMP stack going: Ubuntu 20.04, Nginx, MySQL and PHP (v8). I also got CrowdSec installed (with bouncers for UFW firewall, Nginx and PHP), trying to make sure I'm secure.
I want to host multiple things here. I'm new to Nginx, though I've read several articles today on config. But basically, my goal is the following:
1) A YOURLS server, so I can make my own shortened URLs and stop depending on bit.ly. I'll probably want this to use the main domain name, without a subdomain or subdir - it's sorta the point of an URL shortener. But if necessary, I can create a subdomain.
2) I want to host a NextCloud instance, mostly to share some files with my audience (read only) and host some forms (and stop using Google Forms). I may be able to do all of that with ONLYOFFICE by itself, but NextCloud would give me a lot more. Happy to have this in a subdir, like /nc or even /nextcloud.
3) I'd also like to have a basic, static home page at the root domain, if possible - so that when people go to the base domain name, they have a nice little welcome page with some links and maybe some simple subpages.
I'm not sure how to configure all of this in Nginx. Is this all one "server"? Is it possible to host YOURLS using the base domain and still have a landing page at the main domain? That is, example.com gives a welcome page, but example.com/shorturl invokes YOURLS redirection?
Many tutorials I've found presume you're using Apache. Others assume you're using a subdomain for YOURLS.
One bonus question… can YOURLS redirect from example.com/shorturl to a URL that includes a port number, like othersite.com:9999/some/path? I can't find any documentation on that, and since I haven't actually set up YOURLS yet, I haven't been able to try it out.
Thanks!!
7 Replies
I run YOURLS on my server. It is just a directory under one of the many domains I host on that server…. mydomain.com/shorten is what I call it.
It is no different than the photo gallery called piwigo.com under one of my domains… mydomain2.com/photos.
I don't see what YOURLS has to do with Nginx except the it runs under a virtual host created for Nginx (I assume. I don't use Nginx… Apache works just fine for me… have used it for many years and know it well.)
As for redirection, all YOURLS does is take a long url and 'hashes' into a key that it puts in your database and shows the short 'hash' URL to you to send to someone (unless you make YOURLS 'public' which I don't suggest.) When someone uses your short URL it first goes to your server, hits the database where it is looked up, finds the real (long) URL and redirects to it.
For example, the short URL…
https://mailanc2.net/urls9296/rg7wz
goes to the urls92926 directory on the mailanc2.net domain which looks up the 'key' of 'rg7wz' in the database and finds this long URL:
and goes to it. It is all rather simple.
Thanks for replying. Couple things…
I need to use YOURLS to create custom shortened links, like mydomain.com/CheckThisOut. I chose the mixed case option to hopefully allow me to do this. These URLs will be for my business stuff, so I need them to be memorable. I'd prefer not to have a subdirectory to keep things as simple as possible (not just fewer characters, but easier to remember).
YOURLS is a PHP thing, so it needs a web server. And web servers use configuration to set up routing, which is needed when trying to host more than one "tool" under the same web server, all on the usual HTTP ports (80, 443). Many services like YOURLS seem to presume that they're the only service running on the web server, and so the stock config in the tutorials is for that case.
Honestly, I need to run probably more than two services (I'll want to run some Flask apps at some point, too), so I need to understand how to properly configure Nginx to host multiple services.
OK. What is the purpose of using YOURLS for this? Seems to me that 301 Redirects in .htaccess files would work… or whatever the equivalent is in Nginx. How is YOURLS the right tool for what you want to do?
I want to be able to create multiple shortened URLs, like with bit.ly, but I want to own the service. This won't be open to anyone but me ("private" YOURLS), but I need to create multiple custom, shortened URLs on the fly. For ex, maybe a shortened URL to my podcast episodes, like mydomain.com/ep100.
I don't see the problem. From the YOURLS admin screen you can create custom short URLs to anywhere you want… as well as create several different custom short URLS to the same domain. I guess I still don't understand what the problem is.
I think we got off track. I'm pretty sure that YOURLS will work, as a service, for what I want from YOURLS.
I'm asking about a specific configuration for the server that will allow me to simultaneously host a YOURLS service at the base domain address (allowing for mydomain.com/whatever custom URLs), a static web page at the base address with no path (mydomain.com) AND an instance of NextCloud, accessed at a path like mydomain/nextcloud. I think the first two are fine (maybe using YOURLS "Pages" for the static thing) but I also want an instance of NextCloud on the same Nginx server. I think that's possible, I just can't figure out the Nginx server .conf files for this arrangement.
I've always heard that NextCloud must have its own server but I've never seen that documented anywhere so I doubt it is true. Of course it would depend on how much traffic NetCloud would get as to whether or not you have to dedicate 100% of a server's clock and memory to it.
Go ahead and install everything you want on a Linode and see how it works.