Nginx: Wordpress installed at /home/me/* instead of /var/www/html/* - wordpress

EDIT: All I had to change was the root path in /sites-available/ and change permissions.
So last year I configured my first Nginx server for a Wordpress project. Had the droplet shut off because I was too busy to work on it till now. Long story short...I realized I had Wordpress in my home directory, instead of where I expected it to be /var/www/html/*
Based on my current knowledge, I would use mv for this since /var/www/ does not exist.
If I make the directory /var/www/html/, move everything Wordpress to that directory, and modify the root path in my config file like so
server {
root /var/www/html;
What else has to change?
Tried exactly that and broke it, which I assumed I would. It makes logical sense that that path is referenced elsewhere.
I'm a beginner with Linux and web server config, so pardon my ignorance.
Hoping to learn something, not just be spoon fed the answer
o7

Related

Nginx - Custom configuration files location

I use Nginx with many domains. Some of these domains have custom configurations. I'm including these files inside the server blocks in the Nginx configurations.
For example:
server {
... some configurations things here...
include /var/somewhere/custom.conf;
etc.. etc..
}
The configuration files of Nginx are inside: /etc/nginx
To try and keep everything in one place and not have my custom configuration files all over the place I would like to place my custom configuration files inside /etc/nginx/some_directory
Can I create a sub directory inside /etc/nginx without it causing any issues with Nginx itself? I want to create /etc/nginx/some_directory/ and place my many custom configuration files inside it and include them.
I'm specifically asking this question because I don't want to break something on my production server.
If nginx doesn't know about a directory, it'll not touch it. You can verify that by greping against such pattern in nginx's codebase.
However, messing with a foreign folder structure might cause problems with permissions and ownership of the files, therefore either just use a pre-defined folders nginx prepared for you (/etc/nginx/sites-enabled and /etc/nginx/sites-available) which you can use with symlinks such as nginx itself does
# ls /etc/nginx/sites-enabled
default -> /etc/nginx/sites-available/default
# ls /etc/nginx/sites-available
default
otherwise you're getting into a situation what C/C++ programmers call an undefined behavior and there's no guarantee that what works now will work in the future / nginx doesn't change as well as the distro maintainers might mess with the folder structure and permissions for the packages in distro package manager.
Example:
Nginx might verify the full /etc/nginx tree's permissions and owners - if your folders/files don't match it might cause a warning or crash even. If it's installed by a package manager, it might cause issues when removing the package itself e.g. if the package manager attempts to remove only a known list of folders + afterwards the parent i.e. /etc/nginx by rmdir or similar. Situations you don't really want to get into and debug when you can use allowed folders or symlinks or your own folders that are not bound to an application or behavior except the one you define.

Nginx location and try_files in subdirectory

I'm trying to configure nginx vhost for application and stucked.
App is in directory /site/verb
At this moment app have this kind of links and it is working:
http://example.com/verb/lt.php?some_args=some_args&some_args?some_args
What I need? I need add another link for my clients like below:
http://example.com/v/lt.php?some_args=some_args&some_args?some_args
It is only change from /verb to /v but I want to handle both (for compatibility reasons) with all arguments after .php extension.
Is it possible in nginx config? (I want to avoid creating symlinks in directory).
I tried symlinks but it is not good solution.

Wordpress on Nginx server - .htaccess vs. nginx.conf

I have recently changed from Apache to Nginx server and running a Wordpress installation that was migrated onto this new Nginx server.
I only just realised that (the server provider forgot to mention) that the .htaccess file is no longer supported and shouldn't be used with Nginx.
Instead the nginx.conf file should be used. I know I can convert the contents of my current .htaccess file to nginx.conf using one of the convertors, but I don't even have the nginx.conf file.
Can I just create one?? And If I create one, do I place it into the root where currently my .htaccess file is??
Do I then delete the existing .htaccess file?
How should I go about this?
You definitely have nginx.conf - without it, your site wouldn't work. It is in /etc/nginx/ folder, and some additional configs can exist there and in subfolders.
Standard recommendations for WordPress with nginx you can find here in Codex. But if your site works, you have nothing else to do.
Unlike Apache with .htaccess files, nginx does not use any configuration files in WordPress folders. Everything is centralized in /etc/nginx/.
.htaccess files are ignored by nginx and can be deleted or kept in WordPress folders - it doesn't matter.
However, if you have some non-standard tuning in .htaccess files, you should implement relevant directives in nginx conf files. Convertors not very good for it, and produce errors sometimes, unfortunately. You should learn Apache rules used and create similar for nginx by yourself.

nginx: Looking to serve multiple subdirectories as their own root

Using Nginx, is there was way to run multiple subdirectories as their own self contained roots (document root)?
I am going to have several (40+) projects run in subdirectories:
frontend.example.com/project_1
frontend.example.com/project_2
frontend.example.com/project_3
Each projects are pushed to their own location /var/www/html/project_name. There will not be a site at frontend.example.com
Some projects due to the way they are set up need to run as if they are the root. They contain sources like <img src="/images">. The page is looking at front.example.com/images and not front.example.com/project_a/images.
Can I run each of these projects with the subdirectories as the root folder; stopping at front.example.com/project_name/?
What I've tried that hasn't worked
Creating separate sites-available / sites-enabled and config files. This was tedious since i would need to do this for every site and I kept running into issues. I halted this path to save myself from a rabbit hole, but I can provide those config files, if this is the preferred direction.
What has worked so far...
In sites-available/default having aliases. So having location /images/ look at alias /var/www/html/project_a/images/. This works, but I am hard coding the project_a, and with potentially a lot of separate project, this is not ideal.

Change the path of a symlinked directory in NGINX

Lets say that I have a directory /var/www/assets/ and within that directory I have a symlink which points to a folder which contains all the latest asset files for my website.
/var/www/assets/asssets -> /var/www/website/releases/xxxxxxx/public/assets
If I configure NGINX to serve asset files from /var/www/assets with the domain assetfilesdomain.com and asset files are prefixed with the directory /asset/ then when that /asset folder's symlink is changed then the updated link is not reflected in NGINX. The way that I see it, NGINX grabs the resolved path for that asset folder when it is started.
Is there any way to get around this?
Reloading nginx (sending a HUP signal to the master process) seems to solve this issue (probably because it starts new workers and shuts down the old ones, gracefully).
it seems like you're using Capistrano. You can override deploy:restart and put the nginx reloading there.

Resources